/*获取订单号*/
var orderId = sessionStorage.getItem("orderId");
var dataresult = {}
var result11 = {}
var wuliu = ""
var limitLinedt = "",
    maxLengthdt = "",
    goodTotalWeightdt = "",
    goodTotalVolumedt = "",
    volumeTypedt = "";
var rulerIddt = '';
var may_arrived_begin = ''; //开始时间
var may_arrived_in = ''; //送达时间
if (window.sessionStorage.getItem('rulerId')) {
    rulerIddt = window.sessionStorage.getItem('rulerId')
}
/*通过订单号获取订单详情*/
getOrdertail()

function getOrdertail() {
    $("#datatable").find("tbody").html("")
    $.ajax({
        type: "POST",
        url: root.orderInter.order_queryOrderDetails,
        cache: false, //禁用缓存
        dataType: "json",
        data: {
            order_id: orderId, // 订单编号
        },
        success: function(result) {
            //订单类别默认值
            var order_big_typeall = ''
            limitLinedt = result.orderExt.limit_line;
            maxLengthdt = result.max_edge;
            goodTotalWeightdt = result.total_weight;
            goodTotalVolumedt = result.total_volume;
            //通过时判断 标准达校验
            if (limitLinedt == 20) {
                volumeTypedt = 0
            } else {
                if ((Number(maxLengthdt) <= 4 && Number(goodTotalWeightdt) <= 2000 && Number(goodTotalVolumedt) / 1000000 <= 5)) {
                    volumeTypedt = 10
                }
                if (!(Number(maxLengthdt) <= 4 && Number(goodTotalWeightdt) <= 2000 && Number(goodTotalVolumedt) / 1000000 <= 5)) {
                    volumeTypedt = 20
                }
            }
            if (result.orderAnomal != null && result.orderAnomal != "") {
                if (result.orderAnomal.anomal_type.match('100') || result.orderAnomal.anomal_type.match('20') || result.orderAnomal.anomal_type.match('60') || result.orderAnomal.anomal_type.match('130')) {
                    $("#orderCategory").val(result.orderExt.order_big_type)
                } else {
                    if (result.orderExt.common_order_type == "19653") {
                        //厂家直送
                        $("#orderCategory").val(result.orderExt.order_big_type)
                    } else {
                        $("#orderCategory").val(20)
                    }
                }
            }
            result11 = result;
            may_arrived_begin = result.orderExt.may_arrived_begin;
            may_arrived_in = result.orderExt.may_arrived_in;
            console.log(result)
            sessionStorage.setItem("orderDetail", JSON.stringify(result));
            renderOrderPage(result);
            for (var i = 0; i < result.listOrderVerifyRecord.length; i++) {

                if (result.listOrderVerifyRecord[i].account_type == 10 && result.listOrderVerifyRecord[i].verify_status == 0) {
                    console.log('客户');

                    $("#customerCheck").css({
                        display: "inline"
                    });
                }
            }
            //客户内部审核状态
            if (result.listOrderVerifyRecord != "" || data.listOrderVerifyRecord != null) {
                ordertoexamine(result.listOrderVerifyRecord)
            }
            if (result.orderExt.platform == 10) {
                $("#Customeraudit").css({
                    display: "none"
                });
                //普通平台
            } else if (result.orderExt.platform == 20) {
                $("#Customeraudit").css({
                    display: "block"
                });
            }
            //订单类别(分销超300时不能修改配送方式，临采和超卖的时候可以修改并动态带出订单类别)
            if (result.orderAnomal != null && result.orderAnomal != "") {
                if (result.orderAnomal.anomal_type.match('100')) {
                    console.log("11111111111")
                    if (result.orderAnomal.anomal_type.match('60') || result.orderAnomal.anomal_type.match('20') || result.orderAnomal.anomal_type.match('130')) {
                        $("#orderCategorys").css({
                            display: "inline"
                        });
                    } else {
                        $("#orderCategorys").css({
                            display: "inline"
                        });
                    }

                } else {
                    if (result.orderAnomal.anomal_type.match('60') || result.orderAnomal.anomal_type.match('20') || result.orderAnomal.anomal_type.match('130')) {
                        $("#orderCategorys").css({
                            display: "inline"
                        });
                    } else {
                        $("#orderCategorys").css({
                            display: "none"
                        });
                    }



                }
            }

            //扣额度
            if (result.orderBase.deduct_account_status == 20 && result.orderBase.order_status == 20) {
                $("#deductionAmount").css({
                    display: "inline"
                });

            } else {
                $("#deductionAmount").css({
                    display: "none"
                });

            }

            //配送方式和订单类别
            if (result.orderAnomal != null && result.orderAnomal != "") {
                if ((result.orderAnomal.anomal_type.match('20') || result.orderAnomal.anomal_type.match('60') || result.orderAnomal.anomal_type.match('100') || result.orderAnomal.anomal_type.match('130')) && result.orderExt.sent_type == 40) {
                    $("#sent_type").css({
                        display: "inline"
                    });

                    $("#isSavsdfsfsdeFalse").css({
                        display: "inline"
                    });

                }

                if ((result.orderAnomal.anomal_type.match('20') || result.orderAnomal.anomal_type.match('60') || result.orderAnomal.anomal_type.match('100') || result.orderAnomal.anomal_type.match('130')) && (result.orderExt.sent_type == 10 || result.orderExt.sent_type == 20 || result.orderExt.sent_type == 30 || result.orderExt.sent_type == 21)) {
                    $("#sent_type2").css({
                        display: "inline"
                    });
                    $("#isSavsdfsfsdeFalse").css({
                        display: "inline"
                    });

                }
            }
            //订单类别修改按钮
            if (result.orderExt.sent_type != 50 && (result.orderAnomal.anomal_type.match('20') || result.orderAnomal.anomal_type.match('60') || result.orderAnomal.anomal_type.match('100') || result.orderAnomal.anomal_type.match('120') || result.orderAnomal.anomal_type.match('130')) && result.orderExt.source != 60) {
                $("#modifyordercategory").css({
                    display: "initial"
                });
            } else {
                $("#modifyordercategory").css({
                    display: "none"
                });
            }
            //上门自提
            if (result.orderExt.sent_type == 50) {
                $("#selftakein").css({
                    display: "block"
                });
                $("#selfraisingtime").css({
                    display: "inline-block"
                });
                $("#selftakeshop").css({
                    display: "block"
                });
                $("#receiverdetailaddress").css({
                    display: "block"
                });
                $("#selftakephone").css({
                    display: "block"
                });
                $("#wanna_edin").css({
                    display: "none"
                });
                $("#predixttime").css({
                    display: "none"
                });
                $(".shippingfees").css({
                    display: "none"
                });

            } else {
                $("#selftakein").css({
                    display: "none"
                });
                $("#selfraisingtime").css({
                    display: "none"
                });
                $("#selftakeshop").css({
                    display: "none"
                });
                $("#receiverdetailaddress").css({
                    display: "none"
                });
                $("#selftakephone").css({
                    display: "none"
                });
                $("#wanna_edin").css({
                    display: "block"
                });
                $("#predixttime").css({
                    display: "block"
                });
                $(".shippingfees").css({
                    display: "block"
                });
            }
            //询价单号展示

            if (result.orderExt.order_type == 20 && result.inquiry_num != '') {
                $("#inquirynum").css({
                    display: "inline"
                });
            }
            /*  //更改发货仓按钮（包含缺货超4吨/5方才展示）
              //主订单拆过单和更改过发货仓的不展示，子订单不展示
              if(result.orderAnomal.anomal_type.match('140')){
                  if(result.complementaryWarehouseVO!=null){
                      if(result.order_class==10){
                          //主订单
                          if(result.orderBase.order_split_status!=0 || result.complementaryWarehouseVO.hasChanged !=0){
                              $("#changeWarehouse").css({
                                  display: "none"
                              });
                          }else {
                              $("#changeWarehouse").css({
                                  display: "inline"
                              });
                          }
                      }else {
                          //子订单
                          $("#changeWarehouse").css({
                              display: "none"
                          });
                      }
                  }else {
                      $("#changeWarehouse").css({
                          display: "none"
                      });
                  }
              }else {
                  $("#changeWarehouse").css({
                      display: "none"
                  });
              }*/



            //取消确认按钮
            if (result.orderBase.anomal_check == 10 && (result.orderBase.order_status == 9 || result.orderBase.order_status == 10 || result.orderBase.order_status == 20)) {

                $("#detailCancel").css({
                    display: "inline"
                });
                //通过按钮本展示，现扣额度按钮展示通过按钮就不展示
                if (result.orderBase.deduct_account_status == 20) {
                    $("#pass").css({
                        display: "none"
                    });
                } else {
                    $("#pass").css({
                        display: "inline"
                    });
                }


            }
            //拆单按钮控制
            if (result.orderBase.order_status == 9 && result.orderBase.paid_type == 1101) {
                //拆单按钮展示
                if (result.order_class == 10) {
                    //主订单
                    //拆单按钮
                    if (result.orderAnomal.anomal_type.match('60')) {
                        $("#demolitionOrder").css({
                            display: "inline"
                        });
                    } else {
                        $("#demolitionOrder").css({
                            display: "none"
                        });
                    }

                    if (result.orderBase.order_split_status == 0) {
                        //未拆单可操作按钮展示
                        $("#detailCancel").css({
                            display: "inline"
                        });
                        //通过按钮本展示，现扣额度按钮展示通过按钮就不展示
                        if (result.orderBase.deduct_account_status == 20) {
                            $("#pass").css({
                                display: "none"
                            });
                        } else {
                            $("#pass").css({
                                display: "inline"
                            });
                        }
                        $("#isSaveFalse").css({
                            display: "block"
                        });
                        if (result.orderBase.paid_type == 1101 || result.orderBase.paid_type == 1201 || result.orderBase.paid_type == 1102 || result.orderBase.paid_type == 1103 && result.orderExt.platform == 20) {
                            $("#detail_statue").show();
                        } else {
                            $("#detail_statue").hide();
                        }
                        $("#estimate").css({
                            display: "inline"
                        });
                    } else {
                        //拆单中或者已拆单可操作按钮隐藏
                        $("#detailCancel").css({
                            display: "none"
                        });
                        $("#pass").css({
                            display: "none"
                        });
                        $("#isSaveFalse").css({
                            display: "none"
                        });

                        $("#detail_statue").hide();

                        $("#estimate").css({
                            display: "none"
                        });
                    }

                } else {
                    //子订单
                    $("#demolitionOrder").css({
                        display: "none"
                    });
                    if (result.orderBase.paid_type == 1101 || result.orderBase.paid_type == 1201 || result.orderBase.paid_type == 1102 || result.orderBase.paid_type == 1103 && result.orderExt.platform == 20) {
                        $("#detail_statue").show();
                    } else {
                        $("#detail_statue").hide();
                    }
                }
            } else if (result.orderBase.order_status == 20) {
                //拆单按钮展示
                if (result.order_class == 10) {
                    //主订单
                    //拆单按钮
                    if (result.orderAnomal.anomal_type.match('60')) {
                        $("#demolitionOrder").css({
                            display: "inline"
                        });
                    } else {
                        $("#demolitionOrder").css({
                            display: "none"
                        });
                    }
                    if (result.orderBase.order_split_status == 0) {
                        //未拆单可操作按钮展示
                        $("#detailCancel").css({
                            display: "inline"
                        });
                        //通过按钮本展示，现扣额度按钮展示通过按钮就不展示
                        if (result.orderBase.deduct_account_status == 20) {
                            $("#pass").css({
                                display: "none"
                            });
                        } else {
                            $("#pass").css({
                                display: "inline"
                            });
                        }
                        $("#isSaveFalse").css({
                            display: "block"
                        });
                        if (result.orderBase.paid_type == 1101 || result.orderBase.paid_type == 1201 || result.orderBase.paid_type == 1102 || result.orderBase.paid_type == 1103 && result.orderExt.platform == 20) {
                            $("#detail_statue").show();
                        } else {
                            $("#detail_statue").hide();
                        }
                        $("#estimate").css({
                            display: "inline"
                        });
                    } else {
                        //拆单中或者已拆单可操作按钮隐藏
                        $("#detailCancel").css({
                            display: "none"
                        });
                        $("#pass").css({
                            display: "none"
                        });
                        $("#isSaveFalse").css({
                            display: "none"
                        });

                        $("#detail_statue").hide();

                        $("#estimate").css({
                            display: "none"
                        });
                    }

                } else {
                    //子订单
                    $("#estimate").css({
                        display: "inline"
                    });
                    $("#demolitionOrder").css({
                        display: "none"
                    });
                    if (result.orderBase.paid_type == 1101 || result.orderBase.paid_type == 1201 || result.orderBase.paid_type == 1102 || result.orderBase.paid_type == 1103 && result.orderExt.platform == 20) {
                        $("#detail_statue").show();
                    } else {
                        $("#detail_statue").hide();
                    }
                }
            } else {
                $("#demolitionOrder").css({
                    display: "none"
                });
                if (result.orderBase.paid_type == 1101 || result.orderBase.paid_type == 1201 || result.orderBase.paid_type == 1102 || result.orderBase.paid_type == 1103 && result.orderExt.platform == 20) {
                    $("#detail_statue").show();
                } else {
                    $("#detail_statue").hide();
                }
            }
            //选择订单类型

            if (result.orderBase.order_status == 9) {
                $(".btn-secondary").css({
                    display: "inline"
                });
            }
            if (result.orderBase.order_status == 10) {
                /*待付款的按钮显示*/
                if (result.orderBase.paid_type == 1001 || result.orderBase.paid_type == 1201) {
                    $("#orderSureStatus").css({
                        display: "inline"
                    });
                    $(".btn-secondary").css({
                        display: "none"
                    });
                } else if ((result.orderBase.paid_type == 1301 || result.orderBase.paid_type == 1401) && result.orderBase.customer_verify_status == 10) {
                    $("#orderSureStatus").css({
                        display: "none"
                    });
                    $(".btn-secondary").css({
                        display: "inline"
                    });
                } else if ((result.orderBase.paid_type == 1301 || result.orderBase.paid_type == 1401) && result.orderBase.customer_verify_status != 10) {
                    $("#orderSureStatus").css({
                        display: "inline"
                    });
                    $(".btn-secondary").css({
                        display: "none"
                    });
                }
            } else if (result.orderBase.order_status == 20) {
                /*待审核的按钮显示*/
                if (result.orderBase.customer_verify_status == 10) {
                    $("#orderCheckStatus").css({
                        display: "none"
                    });
                    $(".btn-secondary").css({
                        display: "inline"
                    });
                } else if (result.orderBase.customer_verify_status == 0) {
                    $("#orderCheckStatus").css({
                        display: "inline"
                    });
                    $(".btn-secondary").css({
                        display: "none"
                    });
                }
            }

        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
        }
    });
};

/*转换状态函数*/
function changeOrderState(orderState, paid_type) {
    $("#affirmMoney").siblings().css({
        display: "none"
    });
    switch (orderState) {
        /*订单状态*/
        case 9:
            if (paid_type == 1101) {
                return "待审核";
                break;
            } else {
                return "待付款";
                break;
            }
        case 10:
            return "待付款";
            break;
        case 20:
            return "待审核";
            break;
        case 30:
            return "待配货";
            break;
        case 40:
            return "待出库";
            break;
        case 50:
            return "待发货";
            break;
        case 60:
            return "待收货";
            break;
        case 70:
            return "已收货，待结算";
            break;
        case 80:
            return "订单成功";
            break;
        case 90:
            return "订单完成";
            break;
        case 100:
            return "已取消";
            break;
        case 110:
            return "交易关闭";
            break;
    }
}

function changePayTypeState(payTypeState) {
    switch (payTypeState) {
        /*支付方式*/
        case 1001:
            return "网上支付";
            break;
        case 1002:
            return "支付宝支付";
            break;
        case 1003:
            return "微信支付";
            break;
        case 1101:
            return "货到付款";
            break;
        case 1102:
            return "货到付款-现金";
            break;
        case 1103:
            return "货到付款-pos机";
            break;
        case 1201:
            return "账期支付";
            break;
        case 1301:
            return "银行转账";
            break;
        case 1401:
            return "银行汇票";
            break;
        case 1701:
            return "门店付款";
            break;
    }
}

function changeInvoiceType(invoiceType) {
    switch (invoiceType) {
        /*发票类型*/
        case 10:
            return "增值税";
            break;
        case 20:
            return "普税";
            break;
    }
}

function changies(secondarysenttype) {
    if (result11.orderExt.common_order_type == "19653") {
        switch (secondarysenttype) {
            /*配送方式*/
            case 19653:
                return "厂家直送";
                break;
        }
    } else {
        switch (secondarysenttype) {
            /*配送方式*/
            case 10:
                return "快递";
                break;
            case 20:
                return "快运-送货上门";
                break;
            case 21:
                return "快运-站点自提";
                break;
            case 30:
                return "专车包车";
                break;
            case 40:
                return "鑫方盛物流";
                break;
            case 50:
                return "上门自提";
                break;
            case 52:
                return "配送客户自提";
                break;
        }
    }

}
/*渲染页面*/
/*头部按钮*/

function detailCancel() {
    //权限判断3
    var warehouse_ids = sessionStorage.getItem("regions") //主仓库

    var sales_manager_ids = sessionStorage.getItem("personnels") //人员
    var companys_ids = sessionStorage.getItem("companys") //客户归属

    //都没勾选
    if (warehouse_ids == "" && companys_ids == "") {
        $.Huimodalalert('暂无此订单处理权限！', 2000);
    }
    //只勾选仓
    if (warehouse_ids != "" && companys_ids == "") {

        var warehouse_idsAll = warehouse_ids.split(",");
        var isHas = false;
        for (var i = 0; i < warehouse_idsAll.length; i++) {

            if (warehouse_idsAll[i] == JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.parent_warehouse_id) {
                ishasOrderedGoodsfn()
                    //layer_show("取消该订单", "abnormalCancleAlert.html", "600", "300");
                isHas = true;
                break;
            }
        }
        if (!isHas) {
            $.Huimodalalert('暂无此订单处理权限！', 2000);
        }
    }

    //只勾线分公司
    if (warehouse_ids == "" && companys_ids != "") {
        //有没有勾选分公司
        //子仓库不为空,人员为空时
        if (companys_ids != "" && sales_manager_ids == "") {

            var companys_idAll = companys_ids.split(",");
            var isHas = false;

            for (var t = 0; t < companys_idAll.length; t++) {
                if (companys_idAll[t] == JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.belong_groupId) {
                    ishasOrderedGoodsfn()
                        //layer_show("取消该订单", "abnormalCancleAlert.html", "600", "300");
                    isHas = true;
                    break;
                }

            }
            if (!isHas) {
                $.Huimodalalert('暂无此订单处理权限！', 2000);
            }
        }
        //子仓库,人员不为空时
        if (companys_ids != "" && sales_manager_ids != "") {

            var sales_manager_idsAll = sales_manager_ids.split(",");
            var companys_idAll = companys_ids.split(",");
            var isHas = false;

            for (var j = 0; j < sales_manager_idsAll.length; j++) {
                for (var t = 0; t < companys_idAll.length; t++) {
                    if (sales_manager_idsAll[j] == JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.sales_manager_id || companys_idAll[t] == JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.belong_groupId) {

                        isHas = true;
                        break;
                    }
                }

            }
            if (!isHas) {
                $.Huimodalalert('暂无此订单处理权限！', 2000);
            }
        }
    }
    //仓和分公司
    if (warehouse_ids != "" && companys_ids != "") {
        //主仓不为空，子仓库不为空,人员为空时
        if (warehouse_ids != "" && companys_ids != "" && sales_manager_ids == "") {
            var warehouse_idsAll = warehouse_ids.split(",");

            var companys_idAll = companys_ids.split(",");
            var isHas = false;
            for (var d = 0; d < warehouse_idsAll.length; d++) {

                for (var t = 0; t < companys_idAll.length; t++) {
                    if (warehouse_idsAll[d] == JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.parent_warehouse_id || companys_idAll[t] == JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.belong_groupId) {
                        isHas = true;
                        break;
                    }
                }
            }
            if (!isHas) {
                $.Huimodalalert('暂无此订单处理权限！', 2000);
            } else {
                ishasOrderedGoodsfn()
                    // layer_show("取消该订单", "abnormalCancleAlert.html", "600", "300");
            }
        }
        //主仓不为空，子仓库不为空,人员不为空时
        if (warehouse_ids != "" && companys_ids != "" && sales_manager_ids != "") {
            var warehouse_idsAll = warehouse_ids.split(",");

            var sales_manager_idsAll = sales_manager_ids.split(",");
            var companys_idAll = companys_ids.split(",");
            var isHas = false;
            for (var d = 0; d < warehouse_idsAll.length; d++) {

                for (var f = 0; f < sales_manager_idsAll.length; f++) {
                    for (var t = 0; t < companys_idAll.length; t++) {
                        if (warehouse_idsAll[d] == JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.parent_warehouse_id || sales_manager_idsAll[f] == JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.sales_manager_id || companys_idAll[t] == JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.belong_groupId) {


                            isHas = true;
                            break;
                        }
                    }
                }
            }
            if (!isHas) {
                $.Huimodalalert('暂无此订单处理权限！', 2000);
            } else {
                ishasOrderedGoodsfn()
                    //layer_show("取消该订单", "abnormalCancleAlert.html", "600", "300");
            }
        }

    }
}

function passCheck() {
    //权限判断3
    var warehouse_ids = sessionStorage.getItem("regions") //主仓库

    var sales_manager_ids = sessionStorage.getItem("personnels") //人员
    var companys_ids = sessionStorage.getItem("companys") //客户归属

    //都没勾选
    if (warehouse_ids == "" && companys_ids == "") {
        $.Huimodalalert('暂无此订单处理权限！', 2000);
    }
    //只勾选仓
    if (warehouse_ids != "" && companys_ids == "") {

        var warehouse_idsAll = warehouse_ids.split(",");
        var isHas = false;
        for (var i = 0; i < warehouse_idsAll.length; i++) {

            if (warehouse_idsAll[i] == JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.parent_warehouse_id) {
                //数据
                //验证库存信息
                if (JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.sent_type == 50 && JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.paid_type == 1701) {
                    confirmCollection()
                } else {
                    operationconfirmCollection()
                }
                isHas = true;
                break;
            }
        }
        if (!isHas) {
            $.Huimodalalert('暂无此订单处理权限！', 2000);
        }
    }

    //只勾线分公司
    if (warehouse_ids == "" && companys_ids != "") {
        //有没有勾选分公司
        //子仓库不为空,人员为空时
        if (companys_ids != "" && sales_manager_ids == "") {

            var companys_idAll = companys_ids.split(",");
            var isHas = false;

            for (var t = 0; t < companys_idAll.length; t++) {
                if (companys_idAll[t] == JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.belong_groupId) {

                    //数据
                    //验证库存信息
                    if (JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.sent_type == 50 && JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.paid_type == 1701) {
                        confirmCollection()
                    } else {
                        operationconfirmCollection()
                    }
                    isHas = true;
                    break;
                }

            }
            if (!isHas) {
                $.Huimodalalert('暂无此订单处理权限！', 2000);
            }
        }
        //子仓库,人员不为空时
        if (companys_ids != "" && sales_manager_ids != "") {

            var sales_manager_idsAll = sales_manager_ids.split(",");
            var companys_idAll = companys_ids.split(",");
            var isHas = false;

            for (var j = 0; j < sales_manager_idsAll.length; j++) {
                for (var t = 0; t < companys_idAll.length; t++) {
                    if (sales_manager_idsAll[j] == JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.sales_manager_id || companys_idAll[t] == JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.belong_groupId) {

                        isHas = true;
                        break;
                    }

                }
            }
            if (!isHas) {
                $.Huimodalalert('暂无此订单处理权限！', 2000);
            } else {
                //数据
                //验证库存信息
                if (JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.sent_type == 50 && JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.paid_type == 1701) {
                    confirmCollection()
                } else {
                    operationconfirmCollection()
                }
            }
        }
    }
    //仓和分公司
    if (warehouse_ids != "" && companys_ids != "") {
        //主仓不为空，子仓库不为空,人员为空时
        if (warehouse_ids != "" && companys_ids != "" && sales_manager_ids == "") {
            var warehouse_idsAll = warehouse_ids.split(",");

            var companys_idAll = companys_ids.split(",");
            var isHas = false;
            for (var d = 0; d < warehouse_idsAll.length; d++) {

                for (var t = 0; t < companys_idAll.length; t++) {
                    if (warehouse_idsAll[d] == JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.parent_warehouse_id || companys_idAll[t] == JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.belong_groupId) {
                        isHas = true;
                        break;
                    }
                }
            }
            if (!isHas) {
                $.Huimodalalert('暂无此订单处理权限！', 2000);
            } else {
                //数据
                //验证库存信息
                if (JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.sent_type == 50 && JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.paid_type == 1701) {
                    confirmCollection()
                } else {
                    operationconfirmCollection()
                }
            }
        }
        //主仓不为空，子仓库不为空,人员不为空时
        if (warehouse_ids != "" && companys_ids != "" && sales_manager_ids != "") {
            var warehouse_idsAll = warehouse_ids.split(",");

            var sales_manager_idsAll = sales_manager_ids.split(",");
            var companys_idAll = companys_ids.split(",");
            var isHas = false;
            for (var d = 0; d < warehouse_idsAll.length; d++) {

                for (var f = 0; f < sales_manager_idsAll.length; f++) {
                    for (var t = 0; t < companys_idAll.length; t++) {
                        if (warehouse_idsAll[d] == JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.parent_warehouse_id || sales_manager_idsAll[f] == JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.sales_manager_id || companys_idAll[t] == JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.belong_groupId) {


                            isHas = true;
                            break;
                        }
                    }
                }
            }
            if (!isHas) {
                $.Huimodalalert('暂无此订单处理权限！', 2000);
            } else {
                //数据
                //验证库存信息
                if (JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.sent_type == 50 && JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.paid_type == 1701) {
                    confirmCollection()
                } else {
                    operationconfirmCollection()
                }
            }
        }

    }


}

function ishasOrderedGoodsfn() {
    var params = { orderId: orderId }
    var succCallBack = function(data, status, response) {
        //订单已关联订货单 qq  root.orderInter.validateWhetherOrdered

        // if (data.errorCode == 0) {
        //     if (data.data.hasOrderedGoods) {
        //         var cu = layer.confirm('<span>此订单已关联订货单，是否取消？</span>', { title: '提示', btn: ['确认', '取消'] }, function(index) {
        //             layer_show("取消该订单", "abnormalCancleAlert.html", "600", "300");
        //             layer.close(cu);
        //         }, function() {
        //             layer.close(cu);

        //         });
        //     } else {
        //         layer_show("取消该订单", "abnormalCancleAlert.html", "600", "300");
        //     }
        // } else {
        //     layer_show("取消该订单", "abnormalCancleAlert.html", "600", "300");
        // }、
        layer_show("取消该订单", "abnormalCancleAlert.html", "600", "300");
    }
    web.doAjax(root.orderInter.validateWhetherOrdered, 'POST', params, succCallBack);
}
//通过限制
function confirmCollection() {
    $.ajax({
        type: "POST",
        url: root.orderInter.querySelfTakeProduct,
        cache: false, //禁用缓存
        dataType: "json",
        data: {
            order_id: orderId, // 订单编号
        },
        success: function(result) {
            var commodityInformation = ""
            var datas = result.data
            if (result.errorCode == 0) {
                if (datas != "" && datas != null) {
                    $("#confirmCollection").modal("show")
                    $.each(datas, function(k, v) {
                        //是否弹限制框
                        if (v.occupy_store > 0 && v.occupy_virtual_store == 0) {
                            //白色
                            commodityInformation += '<tr class="commodityInformations">' +
                                '<td class="biaoge1-1" style="width: 60px;"><div style="cursor:pointer;"><img title="" style="float: left;width: 60px;height: 60px;" name="" src="' + v.product_pic + '" alt=""></div></td>' +
                                '<td class="biaoge1-1" style="width: 262px;"><span >' + v.product_name + '</span></td>' +
                                '<td class="biaoge1-2" style="width: 147px;"><span >' + v.sku_info + '</span></td>' +
                                '<td class="biaoge1-3" style="width: 147px;"><span >' + v.color + '</span></td>' +
                                '</tr>';
                        } else if (v.occupy_store > 0 || v.occupy_store == 0 && v.occupy_virtual_store > 0) {
                            //红的
                            commodityInformation += '<tr class="commodityInformations1" bgcolor="#ffb6c1 ">' +
                                '<td class="biaoge1-1" style="width: 60px;"><div style="cursor:pointer;"><img title="" style="float: left;width: 100px;height: 100px;" name="" src="' + v.product_pic + '" alt=""></div></td>' +
                                '<td class="biaoge1-1" style="width: 262px;"><span >' + v.product_name + '</span></td>' +
                                '<td class="biaoge1-2" style="width: 147px;"><span >' + v.sku_info + '</span></td>' +
                                '<td class="biaoge1-3" style="width: 147px;"><span >' + v.color + '</span></td>' +
                                '</tr>';
                        }

                    })
                    $("#confirmCollectiontable").find("tbody").html($(commodityInformation));

                } else {
                    //不弹限制框
                    $("#confirmCollection").modal("hide")
                    operationconfirmCollection()
                }
            } else {
                $.Huimodalalert(result.msg, 2000);
            }


        }
    });
}
//通过正常下推
function operationconfirmCollection() {
    $("#confirmCollection").modal("hide")
    if (JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.sent_type != 50) {
        //当日时间
        var date = new Date();
        var Y = date.getFullYear() + '-';
        var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
        var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
        var timeall = Y + M + D //获取当前系统时间
            //预计送达时间
        var date1 = result11.orderExt.may_arrived_in
        var timearr = date1.replace(" ", ":").replace(/\:/g, "-").split("-");
        var timestr = timearr[0] + "-" + timearr[1] + "-" + timearr[2];
        if (Number(sessionStorage.getItem("senttype")) != 40) {
            if (timestr < timeall) {
                $.Huimodalalert("预计送达时间必须大于当日时间请修改！", 2000);
                return false;
            }
        }
    }



    var secondary_sent_type = ""
    if (result11.orderExt.common_order_type == "19653") {
        secondary_sent_type = changies(result11.orderExt.common_order_type);
    } else {
        secondary_sent_type = changies(result11.orderExt.sent_type);
    }
    if (result11.orderExt.modify_may_arrived == 0) {


        layer.confirm('确认该订单为正常订单？该订单配送方式是' + secondary_sent_type + '', { offset: '230px' }, function(index) {
            if (result11.orderAnomal.anomal_type.match('70')) {
                if (result11.orderAnomal.anomal_type.match('20')) {
                    layer.confirm('请核对临采商品是否已增加物流中心库房，当日有效', { offset: '230px' }, function(index) {
                        updamm()

                    });
                } else {
                    updamm()
                }

            } else {
                //临采商品时提示
                if (result11.orderAnomal.anomal_type.match('20')) {
                    layer.confirm('请核对临采商品是否已增加物流中心库房，当日有效', { offset: '230px' }, function(index) {
                        $.ajax({
                            contentType: "application/json",
                            type: "POST",
                            url: root.orderInter.order_checkAnomalPass,
                            cache: false, //禁用缓存
                            dataType: "json",
                            data: JSON.stringify({
                                order_id: orderId,
                                "deal_name": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
                                "login_account": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.username,
                                "member_id": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
                                "operate_userid": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
                                "operate_username": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
                                "deal_account": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.number,
                                "volumeType": volumeTypedt,
                                "rulerId": rulerIddt

                            }), //传入组装的参数
                            success: function(result) {
                                if (result.code == 0) {
                                    layer.msg('已通过', {
                                        icon: 6,
                                        time: 1000
                                    }, function() {
                                        window.sessionStorage.removeItem("rulerId")
                                        var index = parent.location.reload();
                                        parent.layer.close(index);
                                    });
                                } else {
                                    layer.msg(result.message, {
                                        icon: 5,
                                        time: 3000
                                    });
                                }

                            },
                            error: function(XMLHttpRequest, textStatus, errorThrown) {
                                alert(XMLHttpRequest);
                            }
                        });

                    });
                } else {
                    $.ajax({
                        contentType: "application/json",
                        type: "POST",
                        url: root.orderInter.order_checkAnomalPass,
                        cache: false, //禁用缓存
                        dataType: "json",
                        data: JSON.stringify({
                            order_id: orderId,
                            "deal_name": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
                            "login_account": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.username,
                            "member_id": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
                            "operate_userid": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
                            "operate_username": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
                            "deal_account": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.number,
                            "volumeType": volumeTypedt,
                            "rulerId": rulerIddt

                        }), //传入组装的参数
                        success: function(result) {
                            if (result.code == 0) {
                                layer.msg('已通过', {
                                    icon: 6,
                                    time: 1000
                                }, function() {
                                    window.sessionStorage.removeItem("rulerId")
                                    var index = parent.location.reload();
                                    parent.layer.close(index);
                                });
                            } else {
                                layer.msg(result.message, {
                                    icon: 5,
                                    time: 3000
                                });
                            }
                        },
                        error: function(XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest);
                        }
                    });

                }

            }

        });
    } else {
        layer.confirm('确认该订单为正常订单？该订单配送方式是' + secondary_sent_type + '<br>预计送达时间已修改，请确认是否正确', { offset: '230px' }, function(index) {

            if (result11.orderAnomal.anomal_type.match('20')) {
                layer.confirm('请核对临采商品是否已增加物流中心库房，当日有效', { offset: '230px' }, function(index) {
                    $.ajax({
                        contentType: "application/json",
                        type: "POST",
                        url: root.orderInter.order_checkAnomalPass,
                        cache: false, //禁用缓存
                        dataType: "json",
                        data: JSON.stringify({
                            order_id: orderId,
                            "deal_name": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
                            "login_account": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.username,
                            "member_id": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
                            "operate_userid": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
                            "operate_username": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
                            "deal_account": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.number,
                            "volumeType": volumeTypedt,
                            "rulerId": rulerIddt
                        }), //传入组装的参数
                        success: function(result) {
                            if (result.code == 0) {
                                layer.msg('已通过', {
                                    icon: 6,
                                    time: 1000
                                }, function() {
                                    window.sessionStorage.removeItem("rulerId")
                                    var index = parent.location.reload();
                                    parent.layer.close(index);
                                });
                            } else {
                                layer.msg(result.message, {
                                    icon: 5,
                                    time: 3000
                                });
                            }
                        },
                        error: function(XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest);
                        }
                    });


                });
            } else {
                $.ajax({
                    contentType: "application/json",
                    type: "POST",
                    url: root.orderInter.order_checkAnomalPass,
                    cache: false, //禁用缓存
                    dataType: "json",
                    data: JSON.stringify({
                        order_id: orderId,
                        "deal_name": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
                        "login_account": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.username,
                        "member_id": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
                        "operate_userid": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
                        "operate_username": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
                        "deal_account": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.number,
                        "volumeType": volumeTypedt,
                        "rulerId": rulerIddt
                    }), //传入组装的参数
                    success: function(result) {
                        if (result.code == 0) {
                            layer.msg('已通过', {
                                icon: 6,
                                time: 1000
                            }, function() {
                                window.sessionStorage.removeItem("rulerId")
                                var index = parent.location.reload();
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg(result.message, {
                                icon: 5,
                                time: 3000
                            });
                        }
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert(XMLHttpRequest);
                    }
                });

            }


        });
    }
}
//通过我再想想
function closeconfirmCollection() {
    $("#confirmCollection").modal("hide")
}


function ordertoexamine(data) {
    var verifystatus = "" //审核状态
    var orderAccounts = "" //下单账号
    var verifyAccounts = "" //审核账号
    var verifyPhones = "" //审核手机号
    var verifyAccountsOrder = "" //审核顺序
    var verifyAccountsState = "" //审核状态
    var verifyAccountsTime = "" //审核时间
    var settleAccounts = "" //结算账号
    var settleAccountsTime = "" //下单时间
    var orderAccountArr = []; //下单账号数组
    var verifyAccountArr = []; //审批账号数组
    var settleAccountArr = []; //结算账号数组
    for (var i = 0; i < data.length; i++) {
        if (data[i].account_type == 10) {
            verifyAccountArr.push(data[i])
        } else if (data[i].account_type == 20) {
            settleAccountArr.push(data[i])
        } else if (data[i].account_type == 30) {
            orderAccountArr.push(data[i])
        }
    }
    var verifyAccounttable = ""
    if (verifyAccountArr && verifyAccountArr.length > 0) {

        for (var i = 0; i < verifyAccountArr.length; i++) {
            if (verifyAccountArr[i].verify_status == 0) {
                verifystatus = '未审核' + '<i class="toexamine1"></i>'
            } else if (verifyAccountArr[i].verify_status == 10) {
                verifystatus = "审核通过" + '<i class="toexamine2"></i>'
            } else {
                verifystatus = "审核失败" + '<i class="toexamine3"></i>'
            }
            //审核


            verifyAccounts = verifyAccountArr[i].login_account
            verifyPhones = verifyAccountArr[i].telephone //手机号
                //审核顺序
            if (verifyAccountArr[i].approve_seq == 0) {
                verifyAccountsOrder = "否"
            } else {
                verifyAccountsOrder = verifyAccountArr[i].approve_seq
            }
            //审核状态
            verifyAccountsState = verifystatus
                //审核时间
            if (verifyAccountArr[i].verify_status == 10 && verifyAccountArr[i].operated_at == "1000-01-01 00:00:00") {
                verifyAccountsTime = verifyAccountArr[i].created_at
            } else if (verifyAccountArr[i].verify_status == 10 && verifyAccountArr[i].operated_at != "1000-01-01 00:00:00") {
                verifyAccountsTime = verifyAccountArr[i].operated_at
            } else if (verifyAccountArr[i].verify_status == 0 && verifyAccountArr[i].operated_at == "1000-01-01 00:00:00") {
                verifyAccountsTime = ""
            } else if (verifyAccountArr[i].verify_status == 20) {
                verifyAccountsTime = verifyAccountArr[i].operated_at
            } else {
                verifyAccountsTime = ""
            }

            verifyAccounttable += '<tr>' +
                '                            <td class="orderAccount"></td>' +
                '                            <td class="orderPhone"></td>' +
                '                               <td class="verifyAccount">' + verifyAccounts + '</td>' +
                '                               <td class="verifyPhone">' + verifyPhones + '</td>' +
                '                               <td class="verifyAccountOrder">' + verifyAccountsOrder + '</td>' +
                '                               <td class="verifyAccountState">' + verifyAccountsState + '</td>' +
                '                               <td class="verifyAccountTime">' + verifyAccountsTime + '</td>' +
                '                                     <td class="settleAccount"></td>' +
                '                                     <td class="settlePhone"></td>' +
                '                                     <td class="settleAccountTime"></td>' +
                '                    </tr>'


        }
        $(".toexamine").html(verifyAccounttable);
        //下单
        for (var i = 0; i < orderAccountArr.length; i++) {
            $($(".toexamine").find("tr")[i]).find(".orderAccount").html(orderAccountArr[i].login_account)
            $($(".toexamine").find("tr")[i]).find(".orderPhone").html(orderAccountArr[i].telephone) //手机号

        }
        //结算
        for (var i = 0; i < settleAccountArr.length; i++) {


            if (settleAccountArr[i].verify_status == 10 && settleAccountArr[i].operated_at == "1000-01-01 00:00:00") {
                settleAccountsTime = settleAccountArr[i].created_at
            } else if (settleAccountArr[i].verify_status == 10 && settleAccountArr[i].operated_at != "1000-01-01 00:00:00") {
                settleAccountsTime = settleAccountArr[i].operated_at
            } else if (settleAccountArr[i].verify_status == 0 && settleAccountArr[i].operated_at == "1000-01-01 00:00:00") {
                settleAccountsTime = ""
            } else if (settleAccountArr[i].verify_status == 20) {
                settleAccountsTime = settleAccountArr[i].operated_at
            } else {
                settleAccountsTime = ""
            }

            $($(".toexamine").find("tr")[i]).find(".settleAccount").html(settleAccountArr[i].login_account)
            $($(".toexamine").find("tr")[i]).find(".settlePhone").html(settleAccountArr[i].telephone) //手机号
            $($(".toexamine").find("tr")[i]).find(".settleAccountTime").html(settleAccountsTime)
        }
    } else {
        //下单
        for (var i = 0; i < orderAccountArr.length; i++) {
            verifyAccounttable += '<tr>' +
                '                            <td class="orderAccount">' + orderAccountArr[i].login_account + '</td>' +
                '                            <td class="orderPhone">' + orderAccountArr[i].telephone + '</td>' +
                '                               <td class="verifyAccount"></td>' +
                '                               <td class="verifyPhone"></td>' +
                '                               <td class="verifyAccountOrder"></td>' +
                '                               <td class="verifyAccountState"></td>' +
                '                               <td class="verifyAccountTime"></td>' +
                '                                     <td class="settleAccount"></td>' +
                '                                     <td class="settlePhone"></td>' +
                '                                     <td class="settleAccountTime"></td>' +
                '                    </tr>'
        }
        //结算
        console.log(settleAccountArr)
        $(".toexamine").html(verifyAccounttable);
        for (var i = 0; i < settleAccountArr.length; i++) {

            if (settleAccountArr[i].verify_status == 10 && settleAccountArr[i].operated_at == "1000-01-01 00:00:00") {
                settleAccountsTime = settleAccountArr[i].created_at
            } else if (settleAccountArr[i].verify_status == 10 && settleAccountArr[i].operated_at != "1000-01-01 00:00:00") {
                settleAccountsTime = settleAccountArr[i].operated_at
            } else if (settleAccountArr[i].verify_status == 0 && settleAccountArr[i].operated_at == "1000-01-01 00:00:00") {
                settleAccountsTime = ""
            } else if (settleAccountArr[i].verify_status == 20) {
                settleAccountsTime = settleAccountArr[i].operated_at
            } else {
                settleAccountsTime = ""
            }

            $($(".toexamine").find("tr")[i]).find(".settleAccount").html(settleAccountArr[i].login_account)
            $($(".toexamine").find("tr")[i]).find(".settlePhone").html(settleAccountArr[i].telephone) //手机号
            $($(".toexamine").find("tr")[i]).find(".settleAccountTime").html(settleAccountsTime)
        }


    }
    refreshStock(1)
}

//修改密码
var index = 0;

function updamm() {
    var cu = layer.confirm('<span>存在低于成本价的商品，确认通过？</span><input class="input-text radius" placeholder="请输入密码" type="password" style="padding-left: 10px;" id="remarksr">', { offset: '230px', title: '提示', btn: ['确认', '取消'] }, function(index) {
        fini3()
        layer.close(cu);
    }, function() {
        layer.close(cu);

    });
}
//第二个
function fini3() {
    var remarksr = $("#remarksr").val();
    console.log(remarksr)

    $.ajax({
        url: root.orderInter.checkPriceRevisionPwd,
        cache: false, //禁用缓存
        type: "POST",
        dataType: 'json',
        async: false,
        data: {
            password: $("#remarksr").val().trim()
        },
        success: function(data) {
            if (data.data == 10) {
                $.ajax({
                    contentType: "application/json",
                    type: "POST",
                    url: root.orderInter.order_checkAnomalPass,
                    cache: false, //禁用缓存
                    dataType: "json",
                    data: JSON.stringify({
                        order_id: orderId,
                        "deal_name": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
                        "login_account": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.username,
                        "member_id": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
                        "operate_userid": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
                        "operate_username": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
                        "deal_account": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.number,
                        "volumeType": volumeTypedt,
                        "rulerId": rulerIddt
                    }), //传入组装的参
                    success: function(result) {
                        if (result.code == 0) {
                            layer.msg('已通过', {
                                icon: 6,
                                time: 1000
                            }, function() {
                                window.sessionStorage.removeItem("rulerId")
                                var index = parent.location.reload();
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg(result.message, {
                                icon: 5,
                                time: 3000
                            });
                        }
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert(XMLHttpRequest);
                    }
                });

            } else {
                $.Huimodalalert(data.sub_msg, 2000);
            }


        },
        error: function() {
            $.Huimodalalert('失败！', 2000);
        }
    })


    layer.close(index);
}




/*datatable*/
var dataSource = new Array();
//table的数据源
var table; //table对象
dataSource = [];

function renderOrderPage(data) {
    /*商品总金额计算*/
    var goodsAmount = 0;
    for (var i = 0; i < data.listOrderItems.length; i++) {
        goodsAmount += Number(data.listOrderItems[i].sale_price) * Number(data.listOrderItems[i].buyyer_count);
    }
    $("#goodsAmount").html(goodsAmount.toFixed(2));
    $("#fare").html(data.orderBase.shipping_fee);
    $("#orderAmount").html((goodsAmount + data.orderBase.shipping_fee).toFixed(2));
    /*转换状态*/
    var order_status = changeOrderState(data.orderBase.order_status, data.orderBase.paid_type);
    $("#orderState").html(order_status);
    if ($("#orderState").parent().find("#demolitionOrder").attr('orderstus') == 20) {
        $("#orderState").parent().find("#demolitionOrder").attr('orderstus', 20)
    }
    if ($("#orderState").parent().find("#detailCancel").attr('orderstus') == 20) {
        $("#orderState").parent().find("#detailCancel").attr('orderstus', 20)
    }
    $("#orderId").html(data.orderBase.order_id);
    $("#creatOrderTime").html(data.orderBase.created_at);
    if (data.orderBase.order_status == 10 || data.orderBase.order_status == 50) {
        $(".orderRemark").css({
            display: "none"
        })
    }
    //备注反显
    for (var i = 0; i < data.listOrderRemark.length; i++) {
        if (data.listOrderRemark[i].operate_type == 30) {
            $("#returnReason").html("全部拒收（" + data.listOrderRemark[i].remark + ")")
            $("#closeOptioner").html(data.listOrderRemark[i].operate_username);
        } else if (data.listOrderRemark[i].operate_type == 40) {
            $("#closeOptioner").html(data.listOrderRemark[i].operate_username);
            $("#returnReason").html("全部退货（" + data.listOrderRemark[i].remark + ")");
        }
        if (data.listOrderRemark[i].operate_type == 20) {
            if (data.listOrderRemark[i] == null) {
                $(".orderRemark textarea").val();
            } else {
                $(".orderRemark textarea").val(data.listOrderRemark[i].remark);
            }
        }
        if (data.listOrderRemark[i].operate_type == 10) {

            if (data.listOrderRemark[i] == null) {
                $("#comfirmMoneyRemark").val();
            } else {
                console.log(data.listOrderRemark[i].remark)
                console.log($("#comfirmMoneyRemark"))
                $("#comfirmMoneyRemark").html(data.listOrderRemark[i].remark); //确认认款备注
            }
        }
    }
    //优惠劵，运费卷展示
    if (data.orderCoupon != "" && data.orderCoupon != null) {
        if (data.orderCoupon.coupon_type == 10) {
            $("#couponInfo11").css({
                display: "inline"
            });
        } else {
            $("#couponInfsfo11").css({
                display: "inline"
            });
        }
    }
    /*取消订单记录*/
    if (data.orderCancle != null) {
        $("#cancleTime").html(data.orderCancle.created_at);
        $("#optioner").html(data.orderCancle.created_at);
        $("#cancle-info").html(data.orderCancle.cancel_remark);
    }
    /*关闭订单记录*/
    if (data.orderRefund != null) {
        $("#closeTime").html(data.orderRefund.created_at);
        $("#close-reason").html(changeCloseReason(data.orderRefund.refund_reason));
        $("#close-info").html(data.orderRefund.refund_desc);
    }
    /*基本信息*/

    $("#buyer-name").html(data.orderBase.customer_name);
    $("#created-order-code").html(data.orderBase.login_account);
    $("#receiver-address").html(data.orderExt.receiver_province_name + "" + data.orderExt.receiver_city_name + "" + data.orderExt.receiver_area_name + "" + data.orderExt.receiver_town_name + "" + data.orderExt.receiver_detail_address);
    $("#consignee").html(calculate(data.listAddressReceiver, 1));
    $("#contact-way").html(calculate(data.listAddressReceiver, 2));
    var oop = ""
    if (data.orderExt.lat == "" && data.orderExt.lat == null) {
        oop = data.orderExt.lng
    } else if (data.orderExt.lng == "" && data.orderExt.lng == null) {
        oop = data.orderExt.lat
    } else if (data.orderExt.lng == "" || data.orderExt.lng == null && data.orderExt.lat == "" || data.orderExt.lat == null) {
        oop = ""
    } else {
        oop = data.orderExt.lng + ',' + data.orderExt.lat
        $("#rebuilds").attr("style", "color:#aaaaaa")
        $("#rebuilds").attr("onclick", "") //置灰*/
    }
    $("#lng").html(oop);
    /*鼠标移出事件*/
    $("#consignee").mouseover(function() {
        $("#mouseBox").show();
        $("#mouseBox").html(calculate(data.listAddressReceiver, 1));
    }).mouseout(function() {
        $("#mouseBox").hide();
    })
    $("#contact-way").mouseover(function() {
        $("#mouseBoxTwo").show();
        $("#mouseBoxTwo").html(calculate(data.listAddressReceiver, 3))
    }).mouseout(function() {
        $("#mouseBoxTwo").hide();
    })

    $("#sales-manager").html(data.orderExt.sales_manager_name);
    /*支付与配送方式*/
    $("#pay-type").html(changePayTypeState(data.orderBase.paid_type));
    var big_type = ""
    if (data.orderExt.order_big_type == 10) {
        big_type = '物流配送'
    } else if (data.orderExt.order_big_type == 20) {
        big_type = '店面开票'
    }
    $("#order_big_type").html(big_type);
    $("#warehouse_id").html(data.warehouseName);
    //链接代送
    var receiptno = ''
    if (data.orderExt.common_order_type == 40116) {
        receiptno = '(' + data.orderExt.receipt_no + ')'
    } else {
        receiptno = ''
    }
    $("#common_order_type").html(data.orderTypeName + receiptno);
    $("#sent_type").html(data.sendTypeName);

    wuliu = data.orderExt.sent_type
        //上门自提
    $("#self_take_in").html(data.self_take_in_str);
    $("#self_take_shop").html(data.orderExt.self_take_shop);
    $("#receiver_detail_address").html(data.orderExt.receiver_detail_address);
    $("#self_take_phone").html(data.orderExt.self_take_phone);
    //运费
    //运费
    $("#shippingfee").html((data.orderBase.init_shipping_fee).toFixed(2));
    var yunf = ""
    if (data.orderCoupon != "") {
        if (data.orderBase.used_coupon == 10 && data.orderCoupon.coupon_type == 20) {
            if (data.orderBase.separate_shipping_fee == 10) {
                yunf = (data.orderBase.shipping_fee - data.orderCoupon.coupon_real_value).toFixed(2) + '元' + '&nbsp;&nbsp;' + "(运费单开)"
            } else {
                yunf = "0.00" + '元' + '&nbsp;&nbsp;' + "(运费分摊)"
            }

        } else {
            if (data.orderBase.separate_shipping_fee == 10) {
                yunf = (data.orderBase.shipping_fee).toFixed(2) + '元' + '&nbsp;&nbsp;' + "(运费单开)"
            } else {
                yunf = "0.00" + '元' + '&nbsp;&nbsp;' + "(运费分摊)"
            }

        }
    }


    $("#couponrealvalue").html(yunf);
    $("#freight").html((data.orderBase.shipping_fee).toFixed(2));
    var deliveryTimeType = ""
    if (data.orderExt.deliveryTimeType == 0) {
        deliveryTimeType = "不限时间"
    } else if (data.orderExt.deliveryTimeType == 1) {
        deliveryTimeType = "仅工作日"
    } else if (data.orderExt.deliveryTimeType == 2) {
        deliveryTimeType = "非工作日"
    }
    $("#deliveryTimeType").html(deliveryTimeType);
    //预计送达时间    
    if (data.orderExt.mine_logistics_type == 20) {
        //预计送达时间断
        var predixtDeliveryTime = "";
        //没修改过配送时间
        if (data.orderExt.modify_may_arrived == 0) {
            predixtDeliveryTime = earliestDeliveryTimeCalc(data.orderExt.wanna_arrived_in);
        } else {
            predixtDeliveryTime = earliestDeliveryTimeCalc(data.orderExt.may_arrived_in);
        }
        $("#predixt-delivery-time").html(predixtDeliveryTime);
    } else {
        $("#predixt-delivery-time").html(data.may_arrived);
        if (data.orderExt.may_arrived_in == '1000-01-01 00:00:00') {
            $("#predixt-delivery-time").html("");
        } else if (data.may_arrived == null) {

            $("#predixt-delivery-time").html("");
        } else {
            $("#predixt-delivery-time").html(data.may_arrived);

        }
    }

    $("#inquiry_num").html(data.inquiry_num)

    //期望送达时间
    $("#wanna_arrived_in").html(data.wanna_arrived);
    if (data.wanna_arrived == '1000-01-01 00:00:00') {
        $("#wanna_arrived_in").html("");
    } else if (data.wanna_arrived == null) {

        $("#wanna_arrived_in").html("");
    } else {
        $("#wanna_arrived_in").html(data.wanna_arrived);
    }
    /*优惠券信息*/
    if (data.orderCoupon == null) {
        $("#couponInfo").html("无")
    } else {
        $("#couponInfo").html("满" + data.orderCoupon.use_condition + "元减" + data.orderCoupon.coupon_value + "元")
    }
    if (data.orderCoupon == null) {
        $("#couponInfsfo").html("无")
    } else {
        $("#couponInfsfo").html("满" + data.orderCoupon.use_condition + "元减" + data.orderCoupon.coupon_value + "元")
    }
    $("#longestside").html(data.max_edge + 'm')
    if (data.total_volume < 0.01) {
        $("#volume").html("小于0.01m³")
    } else {
        $("#volume").html(data.total_volume + 'm³')
    }
    $("#weight").html(data.total_weight + 'kg')

    /*结算信息*/
    if (data.orderBase.separate_shipping_fee == 10) {
        $("#goodsAmount").html((data.orderBase.final_total_amount - data.orderBase.shipping_fee - (data.total_promotion_value - data.full_amount_reduce_value - data.full_quantity_reduce_value)).toFixed(2)); //商品金额
        $("#fare").html((data.orderBase.shipping_fee).toFixed(2)); //运费
    } else {
        $("#goodsAmount").html((data.orderBase.final_total_amount - data.orderBase.shipping_fee - (data.total_promotion_value - data.full_amount_reduce_value - data.full_quantity_reduce_value) + data.orderBase.shipping_fee).toFixed(2)); //商品金额
        $("#fare").html("0.00"); //运费
    }
    var aaa = 0.00;
    if (data.orderCoupon != null) {
        if (data.orderCoupon.coupon_type == 10) {
            $("#conMoney").html((data.orderCoupon.coupon_real_value).toFixed(2)); //满减券

        } else if (data.orderCoupon.coupon_type == 20) {
            aaa = data.orderCoupon.coupon_real_value
            $("#conMoney").html("0.00");
        }
        $("#littleFare").html(aaa.toFixed(2)); //运费减免

    } else {
        $("#littleFare").html("0.00");
        $("#conMoney").html("0.00");
    }
    $("#cuxiao").html((data.full_amount_reduce_value + data.full_quantity_reduce_value).toFixed(2));
    $("#integral").html((data.orderBase.used_total_points).toFixed(2));
    $("#orderAmount").html((data.orderBase.paid_amount).toFixed(2)); //订单金额
    var handStr = '';
    var hdStr = '';
    var hdStrdf = ""
    var hdStrdfuu = ""
    var hdSdfuu = ""
    var warehouses = JSON.parse(sessionStorage.getItem("warehouses"))
        //满减金额商品
    if (data.fullAmountReduceOrderItemsMap != "" && data.fullAmountReduceOrderItemsMap != null) {
        var arr = data.fullAmountReduceOrderItemsMap
        $.each(arr, function(index, i) {
            //算出该活动的所有商品小计和优惠值
            let countMoney = 0;
            let promotionMoney = 0;
            $.each(arr[index], function(k, v) {
                promotionMoney = Number(promotionMoney) + Number(v.promotion_value);
                countMoney = Number(countMoney) + Number((v.sale_price * v.buyyer_count).toFixed(2));
            })

            let ruleStr = '<tr><td colspan="11"><div>' +
                '<span style="float: left;">' + arr[index][0].activity_rule + '</span>' +
                '<div style="float: right"><span style="float: left;">￥' + (countMoney).toFixed(2) + '</span><br>' +
                '<span style="float: left;">减：' + (promotionMoney).toFixed(2) + '</span></div>' +
                '</div></td></tr>';
            handStr += ruleStr;

            $.each(arr[index], function(k, v) {
                    console.log(arr[index])


                    var ss = ""
                    $.each(warehouses.data, function(k, s) {
                        if (data.orderBase.parent_warehouse_id == s.warehouseCode) {
                            ss = s.warehouseName
                        }
                    })

                    //运费分摊
                    var fares = ""
                    if (data.orderBase.separate_shipping_fee == 10) {
                        fares = "0"
                    } else {
                        fares = v.fare

                    }
                    //满减券分摊
                    var couponvalues = ""
                    if (data.orderCoupon != "" && data.orderCoupon != null) {

                        if (data.orderCoupon.coupon_type == 10) {
                            couponvalues = v.coupon_value
                        } else {
                            couponvalues = "0"
                        }
                    }
                    //单价
                    var price = v.sale_price
                    var specialPrice = ""
                    if (v.activity_type == 10) {
                        specialPrice = v.promotion_value / v.buyyer_count
                    }
                    price = (price - specialPrice).toFixed(2)

                    var occupystores = ""

                    var cbprice = ""
                    if ((Number(v.sale_price) * Number(v.buyyer_count) - Number(v.promotion_value)) < (Number(v.cost_price) * Number(v.buyyer_count))) {
                        cbprice = "低于成本价"
                    }
                    if ((Number(v.sale_price) * Number(v.buyyer_count) - Number(v.promotion_value)) < (Number(v.cost_price) * Number(v.buyyer_count) * 0.8)) {
                        cbprice = "低于成本价的80%"
                    }
                    var substotle = (price * v.buyyer_count).toFixed(2);
                    var abnormalCauses = "" //异常原因

                    if (v.spu_id == 0) {
                        //临采
                        abnormalCauses += "临采商品<br>"
                        if (v.occupy_virtual_store > 0) {
                            //超卖
                            abnormalCauses += '超卖商品<br>'
                        }
                        if ((Number(v.sale_price) * Number(v.buyyer_count) - Number(v.promotion_value)) < (Number(v.cost_price) * Number(v.buyyer_count))) {
                            //低于成本价
                            abnormalCauses += "低于成本价商品<br>"
                        }
                    } else {
                        if (v.occupy_virtual_store > 0) {
                            //超卖
                            abnormalCauses += '超卖商品<br>'
                        }
                        if ((Number(v.sale_price) * Number(v.buyyer_count) - Number(v.promotion_value)) < (Number(v.cost_price) * Number(v.buyyer_count))) {
                            //低于成本价
                            abnormalCauses += "低于成本价商品<br>"
                        }
                        if (Number(v.manufacturer_sent_limit) != 0) {
                            if (price * v.buyyer_count > Number(v.manufacturer_sent_limit) || Number(price * v.buyyer_count) == Number(v.manufacturer_sent_limit)) {
                                //厂家直送商品
                                abnormalCauses += "厂家直送商品<br>"
                            }
                        }

                    }
                    if (v.occupy_virtual_store > 0) {
                        handStr += '<tr class="biaoge1" >' +
                            '<td class="biaoge1-1"><div style="cursor:pointer;"><img title="" style="float: left;width: 100px;height: 100px;" name="" src="' + v.product_pic + '" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.color + '</div><div>' + v.sku_info + '</div></div></div></td>' +
                            '<td class="biaoge1-1"><span id="handle_man">' + ss + '</span></td>' +
                            '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-6" id="sdf">' + v.occupy_store + '</td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + price + '元/' + v.unit_name + '</span><br><span style="color: #c66161">' + cbprice + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + couponvalues + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + fares + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.promotion_value + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.used_points + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + substotle + '元' + '</span></td>' +
                            '<td class="biaoge1-3"><span class="abnormalCauses">' + abnormalCauses + '</span></td>' +
                            '</tr>';
                    } else {
                        handStr += '<tr class="biaoge1" >' +
                            '<td class="biaoge1-1"><div style="cursor:pointer;"><img title="" style="float: left;width: 100px;height: 100px;" name="" src="' + v.product_pic + '" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.color + '</div><div>' + v.sku_info + '</div></div></div></td>' +
                            '<td class="biaoge1-1"><span id="handle_man">' + ss + '</span></td>' +
                            '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-6" id="sdf">' + v.occupy_store + '</td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + price + '元/' + v.unit_name + '</span><br><span style="color: #c66161">' + cbprice + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + couponvalues + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + fares + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.promotion_value + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.used_points + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + substotle + '元' + '</span></td>' +
                            '<td class="biaoge1-3"><span class="abnormalCauses">' + abnormalCauses + '</span></td>' +
                            '</tr>';
                    }
                }

            )


        })
        $('.biaoge1').children().css('background-color', 'pink');
    }
    //数量商品
    if (data.fullQuantityReduceOrderItemsMap != "" && data.fullQuantityReduceOrderItemsMap != null) {
        var arr = data.fullQuantityReduceOrderItemsMap
        $.each(arr, function(index, i) {
            //算出该活动的所有商品小计和优惠值
            let countMoney = 0;
            let promotionMoney = 0;
            $.each(arr[index], function(k, v) {
                promotionMoney = Number(promotionMoney) + Number(v.promotion_value);
                countMoney = Number(countMoney) + Number((v.sale_price * v.buyyer_count).toFixed(2));
            })

            let ruleStre = '<tr><td colspan="11"><div>' +
                '<span style="float: left;">' + arr[index][0].activity_rule + '</span>' +
                '<div style="float: right"><span style="float: left;">￥' + countMoney + '</span><br>' +
                '<span style="float: left;">减：' + promotionMoney + '</span></div>' +
                '</div></td></tr>';
            hdStrdf += ruleStre;

            $.each(arr[index], function(k, v) {
                console.log(arr[index])
                var ss = ""
                $.each(warehouses.data, function(k, s) {
                        if (data.orderBase.parent_warehouse_id == s.warehouseCode) {
                            ss = s.warehouseName
                        }
                    })
                    //运费分摊
                var fares = ""
                if (data.orderBase.separate_shipping_fee == 10) {
                    fares = "0"
                } else {
                    fares = v.fare

                }
                //满减券分摊
                var couponvalues = ""
                if (data.orderCoupon != "" && data.orderCoupon != null) {

                    if (data.orderCoupon.coupon_type == 10) {
                        couponvalues = v.coupon_value
                    } else {
                        couponvalues = "0"
                    }
                }
                //单价
                var price = v.sale_price
                var specialPrice = ""
                if (v.activity_type == 10) {
                    specialPrice = v.promotion_value / v.buyyer_count
                }
                price = (price - specialPrice).toFixed(2)


                var cbprice = ""
                if ((Number(v.sale_price) * Number(v.buyyer_count) - Number(v.promotion_value)) < (Number(v.cost_price) * Number(v.buyyer_count))) {
                    cbprice = "低于成本价"
                }
                if ((Number(v.sale_price) * Number(v.buyyer_count) - Number(v.promotion_value)) < (Number(v.cost_price) * Number(v.buyyer_count) * 0.8)) {
                    cbprice = "低于成本价的80%"
                }
                var substotle = (price * v.buyyer_count).toFixed(2);
                var abnormalCauses = "" //异常原因

                if (v.spu_id == 0) {
                    //临采
                    abnormalCauses += "临采商品<br>"
                    if (v.occupy_virtual_store > 0) {
                        //超卖
                        abnormalCauses += '超卖商品<br>'
                    }
                    if ((Number(v.sale_price) * Number(v.buyyer_count) - Number(v.promotion_value)) < (Number(v.cost_price) * Number(v.buyyer_count))) {
                        //低于成本价
                        abnormalCauses += "低于成本价商品<br>"
                    }
                } else {
                    if (v.occupy_virtual_store > 0) {
                        //超卖
                        abnormalCauses += '超卖商品<br>'
                    }
                    if ((Number(v.sale_price) * Number(v.buyyer_count) - Number(v.promotion_value)) < (Number(v.cost_price) * Number(v.buyyer_count))) {
                        //低于成本价
                        abnormalCauses += "低于成本价商品<br>"
                    }
                    if (Number(v.manufacturer_sent_limit) != 0) {
                        if (price * v.buyyer_count > Number(v.manufacturer_sent_limit) || Number(price * v.buyyer_count) == Number(v.manufacturer_sent_limit)) {
                            //厂家直送商品
                            abnormalCauses += "厂家直送商品<br>"
                        }
                    }

                }
                if (v.occupy_virtual_store > 0) {
                    hdStrdf += '<tr class="biaoge1" >' +
                        '<td class="biaoge1-1"><div style="cursor:pointer;"><img title="" style="float: left;width: 100px;height: 100px;" name="" src="' + v.product_pic + '" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.color + '</div><div>' + v.sku_info + '</div></div></div></td>' +
                        '<td class="biaoge1-1"><span id="handle_man">' + ss + '</span></td>' +
                        '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                        '<td class="biaoge1-6" id="sdf">' + v.occupy_store + '</td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + price + '元/' + v.unit_name + '</span><br><span style="color: #c66161">' + cbprice + '</span></td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + couponvalues + '</span></td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + fares + '</span></td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + v.promotion_value + '</span></td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + v.used_points + '</span></td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + substotle + '元' + '</span></td>' +
                        '<td class="biaoge1-3"><span class="abnormalCauses">' + abnormalCauses + '</span></td>' +
                        '</tr>';
                } else {
                    hdStrdf += '<tr class="biaoge1" >' +
                        '<td class="biaoge1-1"><div style="cursor:pointer;"><img title="" style="float: left;width: 100px;height: 100px;" name="" src="' + v.product_pic + '" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.color + '</div><div>' + v.sku_info + '</div></div></div></td>' +
                        '<td class="biaoge1-1"><span id="handle_man">' + ss + '</span></td>' +
                        '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                        '<td class="biaoge1-6" id="sdf">' + v.occupy_store + '</td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + price + '元/' + v.unit_name + '</span><br><span style="color: #c66161">' + cbprice + '</span></td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + couponvalues + '</span></td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + fares + '</span></td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + v.promotion_value + '</span></td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + v.used_points + '</span></td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + substotle + '元' + '</span></td>' +
                        '<td class="biaoge1-3"><span class="abnormalCauses">' + abnormalCauses + '</span></td>' +
                        '</tr>';
                }
            })


        })
    }
    //特价商品
    if (data.specialPriceOrderItemsList != "" && data.specialPriceOrderItemsList != null) {
        var arr = data.specialPriceOrderItemsList

        //算出该活动的所有商品小计和优惠值
        let ii = ""
        let ruleStret = '<tr><td colspan="11"><div>' +
            '<span style="float: left;">' + ii + '</span>' +
            '</div></td></tr>';
        hdStrdfuu += ruleStret;

        $.each(arr, function(k, v) {
            var ss = ""
            $.each(warehouses.data, function(k, s) {
                    if (data.orderBase.parent_warehouse_id == s.warehouseCode) {
                        ss = s.warehouseName
                    }
                })
                //运费分摊
            var fares = ""
            if (data.orderBase.separate_shipping_fee == 10) {
                fares = "0"
            } else {
                fares = v.fare

            }
            //满减券分摊
            var couponvalues = ""
            if (data.orderCoupon != "" && data.orderCoupon != null) {

                if (data.orderCoupon.coupon_type == 10) {
                    couponvalues = v.coupon_value
                } else {
                    couponvalues = "0"
                }
            }
            //单价
            var price = v.sale_price
            var specialPrice = ""
            if (v.activity_type == 10) {
                specialPrice = v.promotion_value / v.buyyer_count
            }
            price = (price - specialPrice).toFixed(2)

            var cbprice = ""
            if ((Number(v.sale_price) * Number(v.buyyer_count) - Number(v.promotion_value)) < (Number(v.cost_price) * Number(v.buyyer_count))) {
                cbprice = "低于成本价"
            }
            if ((Number(v.sale_price) * Number(v.buyyer_count) - Number(v.promotion_value)) < (Number(v.cost_price) * Number(v.buyyer_count) * 0.8)) {
                cbprice = "低于成本价的80%"
            }
            var substotle = (price * v.buyyer_count).toFixed(2);
            var abnormalCauses = "" //异常原因

            if (v.spu_id == 0) {
                //临采
                abnormalCauses += "临采商品<br>"
                if (v.occupy_virtual_store > 0) {
                    //超卖
                    abnormalCauses += '超卖商品<br>'
                }
                if ((Number(v.sale_price) * Number(v.buyyer_count) - Number(v.promotion_value)) < (Number(v.cost_price) * Number(v.buyyer_count))) {
                    //低于成本价
                    abnormalCauses += "低于成本价商品<br>"
                }
            } else {
                if (v.occupy_virtual_store > 0) {
                    //超卖
                    abnormalCauses += '超卖商品<br>'
                }
                if ((Number(v.sale_price) * Number(v.buyyer_count) - Number(v.promotion_value)) < (Number(v.cost_price) * Number(v.buyyer_count))) {
                    //低于成本价
                    abnormalCauses += "低于成本价商品<br>"
                }
                if (Number(v.manufacturer_sent_limit) != 0) {
                    if (price * v.buyyer_count > Number(v.manufacturer_sent_limit) || Number(price * v.buyyer_count) == Number(v.manufacturer_sent_limit)) {
                        //厂家直送商品
                        abnormalCauses += "厂家直送商品<br>"
                    }
                }

            }
            if (v.occupy_virtual_store > 0) {
                hdStrdfuu += '<tr class="biaoge1" >' +
                    '<td class="biaoge1-1"><div style="cursor:pointer;"><img title="" onclick="goToGoodsDetail(' + v.spu_id + ')" style="float: left;width: 100px;height: 100px;" name="" src="' + v.product_pic + '" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.color + '</div><div>' + v.sku_info + '</div></div></div></td>' +
                    '<td class="biaoge1-1"><span id="handle_man">' + ss + '</span></td>' +
                    '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                    '<td class="biaoge1-6">' + v.occupy_store + '</td>' +
                    '<td class="biaoge1-3"><div><input style="width: 32px;background-color: yellow;" value="特价" readonly="readonly"></div><span id="create_time">' + price + '元/' + v.unit_name + '</span><br><span style="color: #c66161">' + cbprice + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + couponvalues + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + fares + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + "0" + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + v.used_points + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + substotle + '元' + '</span></td>' +
                    '<td class="biaoge1-3"><span class="abnormalCauses">' + abnormalCauses + '</span></td>' +
                    '</tr>';
            } else {
                hdStrdfuu += '<tr class="biaoge1">' +
                    '<td class="biaoge1-1"><div style="cursor:pointer;"><img title="点击跳转sku列表" onclick="goToGoodsDetail(' + v.spu_id + ')" style="float: left;width: 100px;height: 100px;" name="" src="' + v.product_pic + '" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.color + '</div><div>' + v.sku_info + '</div></div></div></td>' +
                    '<td class="biaoge1-1"><span id="handle_man">' + ss + '</span></td>' +
                    '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                    '<td class="biaoge1-6">' + v.occupy_store + '</td>' +
                    '<td class="biaoge1-3"><div><input style="width: 32px;background-color: yellow;" value="特价" readonly="readonly"></div><span id="create_time">' + price + '元/' + v.unit_name + '</span><br><span style="color: #c66161">' + cbprice + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + couponvalues + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + fares + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + "0" + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + v.used_points + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + substotle + '元' + '</span></td>' +
                    '<td class="biaoge1-3"><span class="abnormalCauses">' + abnormalCauses + '</span></td>' +
                    '</tr>';
            }


        })



    }

    if (data.normalPriceOrderItemsList != "" && data.normalPriceOrderItemsList != null) {
        var arr = data.normalPriceOrderItemsList

        //算出该活动的所有商品小计和优惠值
        let ii = ""
        let ruleStret = '<tr><td colspan="11"><div>' +
            '<span style="float: left;">' + ii + '</span>' +
            '</div></td></tr>';
        hdSdfuu += ruleStret;

        $.each(arr, function(k, v) {
            var ss = ""
            $.each(warehouses.data, function(k, s) {
                    if (data.orderBase.parent_warehouse_id == s.warehouseCode) {
                        ss = s.warehouseName
                    }
                })
                //运费分摊
            var fares = ""
            if (data.orderBase.separate_shipping_fee == 10) {
                fares = "0"
            } else {
                fares = v.fare

            }
            //满减券分摊
            var couponvalues = ""
            if (data.orderCoupon != "" && data.orderCoupon != null) {

                if (data.orderCoupon.coupon_type == 10) {
                    couponvalues = v.coupon_value
                } else {
                    couponvalues = "0"
                }
            }
            //单价
            var price = v.sale_price
            var specialPrice = ""
            if (v.activity_type == 10) {
                specialPrice = v.promotion_value / v.buyyer_count
            }
            price = (price - specialPrice).toFixed(2)

            var cbprice = ""
            if ((Number(v.sale_price) * Number(v.buyyer_count) - Number(v.promotion_value)) < (Number(v.cost_price) * Number(v.buyyer_count))) {
                cbprice = "低于成本价"
            }
            if ((Number(v.sale_price) * Number(v.buyyer_count) - Number(v.promotion_value)) < (Number(v.cost_price) * Number(v.buyyer_count) * 0.8)) {
                cbprice = "低于成本价的80%"
            }
            var substotle = (price * v.buyyer_count).toFixed(2);
            var abnormalCauses = "" //异常原因

            if (v.spu_id == 0) {
                //临采
                abnormalCauses += "临采商品<br>"
                if (v.occupy_virtual_store > 0) {
                    //超卖
                    abnormalCauses += '超卖商品<br>'
                }
                if ((Number(v.sale_price) * Number(v.buyyer_count) - Number(v.promotion_value)) < (Number(v.cost_price) * Number(v.buyyer_count))) {
                    //低于成本价
                    abnormalCauses += "低于成本价商品<br>"
                }
            } else {
                if (v.occupy_virtual_store > 0) {
                    //超卖
                    abnormalCauses += '超卖商品<br>'
                }
                if ((Number(v.sale_price) * Number(v.buyyer_count) - Number(v.promotion_value)) < (Number(v.cost_price) * Number(v.buyyer_count))) {
                    //低于成本价
                    abnormalCauses += "低于成本价商品<br>"
                }
                if (Number(v.manufacturer_sent_limit) != 0) {
                    if (price * v.buyyer_count > Number(v.manufacturer_sent_limit) || Number(price * v.buyyer_count) == Number(v.manufacturer_sent_limit)) {
                        //厂家直送商品
                        abnormalCauses += "厂家直送商品<br>"
                    }
                }

            }



            if (v.occupy_virtual_store > 0) {
                hdSdfuu += '<tr class="biaoge1">' +
                    '<td class="biaoge1-1"><div style="cursor:pointer;"><img title="" style="float: left;width: 100px;height: 100px;" onclick="goToGoodsDetail(' + v.spu_id + ')" name="" src="' + v.product_pic + '" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.color + '</div><div>' + v.sku_info + '</div></div></div></td>' +
                    '<td class="biaoge1-1"><span id="handle_man">' + ss + '</span></td>' +
                    '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                    '<td class="biaoge1-6">' + v.occupy_store + '</td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + price + '元/' + v.unit_name + '</span><br><span style="color: #c66161">' + cbprice + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + couponvalues + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + fares + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + v.promotion_value + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + v.used_points + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + substotle + '元' + '</span></td>' +
                    '<td class="biaoge1-3"><span class="abnormalCauses">' + abnormalCauses + '</span></td>' +
                    '</tr>';
            } else {
                hdSdfuu += '<tr class="biaoge1">' +
                    '<td class="biaoge1-1"><div style="cursor:pointer;"><img title="点击跳转sku列表" onclick="goToGoodsDetail(' + v.spu_id + ')" style="float: left;width: 100px;height: 100px;" name="" src="' + v.product_pic + '" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.color + '</div><div>' + v.sku_info + '</div></div></div></td>' +
                    '<td class="biaoge1-1"><span id="handle_man">' + ss + '</span></td>' +
                    '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                    '<td class="biaoge1-6">' + v.occupy_store + '</td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + price + '元/' + v.unit_name + '</span><br><span style="color: #c66161">' + cbprice + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + couponvalues + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + fares + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + v.promotion_value + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + v.used_points + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + substotle + '元' + '</span></td>' +
                    '<td class="biaoge1-3"><span class="abnormalCauses">' + abnormalCauses + '</span></td>' +
                    '</tr>';
            }
        })



    }
    $("#datatable").find("tbody").append($(handStr));
    $("#datatable").find("tbody").append($(hdStrdf));
    $("#datatable").find("tbody").append($(hdStrdfuu));
    $("#datatable").find("tbody").append($(hdSdfuu));
    productLists()
}

function productLists() {
    var abnormalCauses1 = false
    var abnormalCauses2 = false
    var abnormalCauses3 = false
    var productList = $('#datatable tr');
    for (var j = 0; j < productList.length; j++) {
        if ($(productList[j]).find('.abnormalCauses').html() != undefined) {
            if ($(productList[j]).find('.abnormalCauses').html().indexOf("厂家直送商品") == 0) {
                abnormalCauses1 = true
            }
            if ($(productList[j]).find('.abnormalCauses').html().indexOf("低于成本价商品") == 0) {
                abnormalCauses2 = true
            }
            if ($(productList[j]).find('.abnormalCauses').html() == "") {
                //正常商品
                abnormalCauses3 = true
            }

        }
    }
}


/*订单备注编辑*/
var oldVal = "";

function toEdit() {
    oldVal = $(".orderRemark textarea").val();
    $("#isSaveFalse").css({
        display: "none"
    });
    $("#isSaveTrue").css({
        display: "block"
    });
    $(".orderRemark textarea").removeAttr("readonly");
}

function toCancle() {
    $(".orderRemark textarea").val(oldVal);
    $("#isSaveFalse").css({
        display: "block"
    });
    $("#isSaveTrue").css({
        display: "none"
    });
    $(".orderRemark textarea").attr("readonly", "readonly");
}

function calculate(listAddressReceiver, type) {
    var math = ""
    var phone = ""
    var he = ""
    var size = listAddressReceiver.length
    if (listAddressReceiver.length == 0) {
        return "";
    }
    for (i = 0; i < size; i++) {
        if (i < size - 1) {
            math += listAddressReceiver[i].receiver_name + " ;"
            phone += listAddressReceiver[i].mobile + " ; "
            if (i % 2 != 0) {
                he += listAddressReceiver[i].receiver_name + listAddressReceiver[i].mobile + " ; <br/> "
            } else {
                he += listAddressReceiver[i].receiver_name + listAddressReceiver[i].mobile + " ;  "
            }
        } else {
            math += listAddressReceiver[i].receiver_name
            phone += listAddressReceiver[i].mobile
            if (i % 2 != 0) {
                he += listAddressReceiver[i].receiver_name + listAddressReceiver[i].mobile + "  <br/> "
            } else {
                he += listAddressReceiver[i].receiver_name + listAddressReceiver[i].mobile + "   "
            }
        }
    }
    if (type == 1) {
        return math
    } else if (type == 2) {
        return phone
    } else if (type == 3) {
        return he
    }
}

function remarkToSave() {
    var orderDetail = JSON.parse(sessionStorage.getItem("orderDetail"));
    var orderState = orderDetail.orderBase.order_status;

    function btnDisplay() {
        $("#isSaveFalse").css({
            display: "block"
        });
        $("#isSaveTrue").css({
            display: "none"
        });
        $(".orderRemark textarea").attr("readonly", "readonly");
    }
    /*进行添加备注请求*/
    btnDisplay();
    $.ajax({
        contentType: "application/json",
        type: "POST",
        url: root.orderInter.order_saveOrderRemark,
        cache: false, //禁用缓存
        dataType: "json",
        data: JSON.stringify({
            bus_id: orderDetail.orderBase.order_id,
            operate_userid: JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
            operate_username: JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
            remark: $("#remarkVal").val()


        }),
        success: function(result) {
            location.replace(location.href);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
        }
    });
}

/*详细信息编辑*/
function requireUpdataInter(updataData) {
    $.ajax({
        contentType: "application/json",
        type: "POST",
        url: root.orderInter.order_edit,
        cache: false, //禁用缓存
        dataType: "json",
        data: updataData,
        success: function(result) {
            console.log(result)
            if (result.code == 0) {
                $("#addressInpBox").css({
                    display: "none",
                })
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
        }
    });
}

function updataDisplay(ids) {
    $(ids).css({
        display: "block",
    })
}

//跳转拒收
function clientRejection(title, url) {
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}
var isIngReturn = false;

function returnGoods(title) {
    if (isIngReturn) {
        // layer.msg('请求已提交，请勿重复点击！');
        return false;
    }
    isIngReturn = true;
    getOrdertail()
    setTimeout(function() {
        var orderDetail = JSON.parse(sessionStorage.getItem("orderDetail"));
        var orderState = orderDetail.orderBase.order_status;

        var url = "orderSuccess_refund2.html";

        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }, 200)
}

function updataSure(val) {
    var orderDetail = JSON.parse(sessionStorage.getItem("orderDetail"));
    console.log(val)
    switch (val) {
        /*发票类型*/
        case "#addressInp":
            var updataData = JSON.stringify({
                order_id: orderDetail.orderBase.order_id,
                receiver_detail_address: $('#addressInp').val(),
            });
            requireUpdataInter(updataData)
            break;
        case "#consigneeInp":
            var updataData = JSON.stringify({
                order_id: orderDetail.orderBase.order_id,
                received_name: $('#consigneeInp').val(),
            });
            requireUpdataInter(updataData)
            break;
    }
    console.log();
}

function updataCancel() {
    $("#addressInpBox").css({
        display: "none",
    });
    $("#consigneeInpBox").css({
        display: "none",
    });
}

function goToGoodsDetail(code) {
    console.log("商品列表");
    if (code == "0") {
        return false;
    }
    var index = layer.open({
        type: 2,
        title: "商品详情",
        content: "https://" + window.location.host + "/productspu/" + code + ".html"
    });
    layer.full(index);
}
//客户状态查询
function bstart() {
    $.ajax({
        url: root.orderInter.checkRestrictCustomer,
        cache: false, //禁用缓存
        type: "POST",
        dataType: 'json',
        async: false,
        data: {
            "order_id": orderId
        },
        success: function(result) {
            dataresult = result;
            if (result.errorCode == 0) {

                if (result.data.isRestrictCustomer == 1) {
                    $("#start1").html("限制类客户")
                    $("#start2").html('信用额度：' + result.data.creditTotal + '')
                    $("#start3").html('可用额度：' + result.data.availableCredit + '')
                    abstart();
                } else if (result.data.isRestrictCustomer == 0) {
                    $("#start1").html("正常客户")
                    $("#start2").html('信用额度：' + result.data.creditTotal + '')
                    $("#start3").html('可用额度：' + result.data.availableCredit + '')

                }
            } else {
                $.Huimodalalert(result.msg, 2000);
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
        }
    });

}

function abstart() {
    dataresult;
    console.log(dataresult)
    layer.confirm('该客户为限制类客户,信用额度为' + dataresult.data.creditTotal + ',可用额度为' + dataresult.data.availableCredit + ',是否通过？', { offset: '230px' }, function(index) {
        $.ajax({
            contentType: "application/json",
            type: "POST",
            url: root.orderInter.order_checkAnomalPass,
            cache: false, //禁用缓存
            dataType: "json",
            data: JSON.stringify({
                order_id: orderId,
                "deal_name": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
                "login_account": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.username,
                "member_id": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
                "operate_userid": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
                "operate_username": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
                "deal_account": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.number,
                "volumeType": volumeTypedt,
                "rulerId": rulerIddt
            }), //传入组装的参数
            success: function(result) {
                if (result.code == 0) {
                    layer.msg('已通过', {
                        icon: 6,
                        time: 1000
                    }, function() {
                        var index = parent.location.reload();
                        parent.layer.close(index);
                    });
                } else {
                    layer.msg(result.message, {
                        icon: 5,
                        time: 3000
                    });
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest);
            }
        });

    });

}



function estimate() {
    var timedt = new Date();
    var monthd = timedt.getMonth() + 1
    var newdatimedt = timedt.getFullYear() + '-' + monthd + '-' + timedt.getDate() + ' ' + timedt.getHours() + ':' + timedt.getMinutes() + ':' + timedt.getSeconds();
    sessionStorage.setItem('newdatime', JSON.stringify(newdatimedt))
    sessionStorage.setItem("orderIds", orderId)
    sessionStorage.setItem("senttype", wuliu)
        //预计送达时间 修改为 标准达 加急配送（按照原有的逻辑）
    sessionStorage.setItem("limitLine", limitLinedt)
    sessionStorage.setItem("maxLength", maxLengthdt)
    sessionStorage.setItem("goodTotalWeight", goodTotalWeightdt)
    sessionStorage.setItem("goodTotalVolume", goodTotalVolumedt)
        // var deliveryTime=$("#predixt-delivery-time").attr('data-time').split(' ')
    layer_show("修改时间", "estimate.html?timedt=" + may_arrived_begin + "&deliveryTime=" + may_arrived_in, "800", "500");
}
//操作日志
function operationlog() {
    sessionStorage.setItem("orderIds", orderId)
    var title = "操作日志"
    var url = "operationLog.html"
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}

//验证更改发货仓
function demolitionOrderall() {
    if (JSON.parse(sessionStorage.getItem("orderDetail")).orderAnomal.anomal_type.match('140') && JSON.parse(sessionStorage.getItem("orderDetail")).complementaryWarehouseVO != null) {

        if (JSON.parse(sessionStorage.getItem("orderDetail")).order_class == 10) {
            //主订单
            //未拆过单
            if (JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.order_split_status == 0) {
                //更改发货仓按钮（包含缺货超4吨/5方才提示）
                //主订单拆过单和更改过发货仓的不提示，子订单不提示
                if (JSON.parse(sessionStorage.getItem("orderDetail")).complementaryWarehouseVO.hasChanged == 0) {
                    var curInd = layer.confirm('<span>请先更改发货仓</span>' + '<br/>', {
                        offset: '230px',
                        title: '提示',
                        btn: ['确定']
                    }, function(index) {
                        layer.close(curInd);

                    });

                } else {
                    demolitionOrder()
                }
            } else {
                demolitionOrder()
            }
        } else {
            //子订单
            demolitionOrder()
        }
    } else {
        demolitionOrder()
    }

}
//拆单
function demolitionOrder() {
    var params = { orderId: orderId }
    var succCallBack = function(data, status, response) {
        // if (data.errorCode == 0) {
        //     if (data.data.hasOrderedGoods == true && JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.order_split_status == 0) {//已关联且未拆分  待审核
        //         $.Huimodalalert('此订单已制作订货单，无法拆单',2000);
        //         return
        //     }else{
        //         var orderDetail = JSON.parse(sessionStorage.getItem("orderDetail"));
        //         if(orderDetail.orderBase.order_split_status==0){
        //             var curInd = layer.confirm('<span>确认是否拆单？一旦操作，主订单将被锁定（仅可查看）！</span>'+'<br/>', {offset:'230px',title:'提示',btn: ['确定', '取消']}, function(index){
        //                 $.ajax({
        //                     url:root.orderInter.lockOrder,
        //                     cache: false,  //禁用缓存
        //                     type: "POST",
        //                     dataType:'json',
        //                     contentType: "application/json",
        //                     data: JSON.stringify({
        //                         "order_id":orderId,
        //                         "operate_userid":JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
        //                         "operate_username":JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
        //                     }),
        //                     success: function (data) {
        //                         if(data.errorCode==0){
        //                             sessionStorage.setItem("demolitionOrderId",orderId)
        //                             var title="拆单"
        //                             var url="demolitionOrder.html"
        //                             var index = layer.open({
        //                                 type: 2,
        //                                 title: title,
        //                                 content: url,
        //                                 end:function () {
        //                                     location.replace(location.href)
        //                                 }
        //                             });
        //                             layer.full(index);

        //                         }else {

        //                             $.Huimodalalert(data.msg,2000);

        //                         }
        //                     },
        //                     error: function () {
        //                         $.Huimodalalert('失败！',2000);
        //                     }
        //                 })


        //                 layer.close(curInd);

        //             },function(){
        //                 layer.close(curInd);

        //             });
        //         }else {
        //             sessionStorage.setItem("demolitionOrderId",orderId)
        //             var title="拆单"
        //             var url="demolitionOrder.html"
        //             var index = layer.open({
        //                 type: 2,
        //                 title: title,
        //                 content: url,
        //                 /* 关闭弹出框的回调函数*/
        //                 end:function () {
        //                     location.replace(location.href)
        //                 }
        //             });
        //             layer.full(index);
        //         }
        //     }
        // }
        var orderDetail = JSON.parse(sessionStorage.getItem("orderDetail"));
        if (orderDetail.orderBase.order_split_status == 0) {
            var curInd = layer.confirm('<span>确认是否拆单？一旦操作，主订单将被锁定（仅可查看）！</span>' + '<br/>', { offset: '230px', title: '提示', btn: ['确定', '取消'] }, function(index) {
                $.ajax({
                    url: root.orderInter.lockOrder,
                    cache: false, //禁用缓存
                    type: "POST",
                    dataType: 'json',
                    contentType: "application/json",
                    data: JSON.stringify({
                        "order_id": orderId,
                        "operate_userid": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
                        "operate_username": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
                    }),
                    success: function(data) {
                        if (data.errorCode == 0) {
                            sessionStorage.setItem("demolitionOrderId", orderId)
                            var title = "拆单"
                            var url = "demolitionOrder.html"
                            var index = layer.open({
                                type: 2,
                                title: title,
                                content: url,
                                end: function() {
                                    location.replace(location.href)
                                }
                            });
                            layer.full(index);

                        } else {

                            $.Huimodalalert(data.msg, 2000);

                        }
                    },
                    error: function() {
                        $.Huimodalalert('失败！', 2000);
                    }
                })


                layer.close(curInd);

            }, function() {
                layer.close(curInd);

            });
        } else {
            sessionStorage.setItem("demolitionOrderId", orderId)
            var title = "拆单"
            var url = "demolitionOrder.html"
            var index = layer.open({
                type: 2,
                title: title,
                content: url,
                /* 关闭弹出框的回调函数*/
                end: function() {
                    location.replace(location.href)
                }
            });
            layer.full(index);
        }
    }
    web.doAjax(root.orderInter.validateWhetherOrdered, 'POST', params, succCallBack);



}
//重新生成经纬度
function rebuilds() {
    $.ajax({
        url: root.orderInter.updateLngAndLat,
        cache: false, //禁用缓存
        type: "POST",
        dataType: 'json',
        contentType: "application/json",
        data: JSON.stringify({
            "order_id": orderId,
            "operate_userid": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
            "operate_username": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
        }),
        success: function(data) {
            if (data.errorCode == 0) {
                $.Huimodalalert("经纬度已生成", 2000);
                getOrdertail();
                if (data.msg && data.msg != 'SUCCESS') {
                    setTimeout(function() { $.Huimodalalert(data.msg, 2000); }, 2500);
                }

            } else {
                $.Huimodalalert(data.msg, 2000);

            }
        },
        error: function() {
            $.Huimodalalert('失败！', 2000);
        }
    })
}
//订单类别编辑
function editorderCategory() {
    $("#orderCategory").removeAttr("disabled");

    $("#isseTrue").css({
        display: "inline"
    });
    $("#isSasdeFalse").css({
        display: "none"
    });
}
//订单类别取消
function orderCategoryclose() {
    $("#orderCategory").attr("disabled", "disabled");
    $("#isseTrue").css({
        display: "none"
    });
    $("#isSasdeFalse").css({
        display: "inline"
    });
    getOrdertail()
}
//订单类别保存
function orderCategoryadd() {
    $.ajax({
        contentType: "application/json;charset=UTF-8",
        url: root.orderInter.updateOrderBigType,
        cache: false, //禁用缓存
        type: "POST",
        dataType: 'json',
        data: JSON.stringify({
            "order_id": orderId,
            "operate_userid": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
            "operate_username": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
            "order_big_type": $("#orderCategory").val()

        }),
        success: function(data) {
            if (data.errorCode == 0) {
                $.Huimodalalert('编辑成功', 2000);
                $("#orderCategory").attr("disabled", "disabled");
                $("#isseTrue").css({
                    display: "none"
                });
                $("#isSasdeFalse").css({
                    display: "inline"
                });
                getOrdertail()
            } else {
                $.Huimodalalert(data.msg, 2000);
            }

        },
        error: function() {
            $.Huimodalalert('失败！', 2000);
        }
    })
}
//刷新库存
function refreshStock(val) {
    $.ajax({
        type: "POST",
        url: root.orderInter.queryOrderSplitDetails,
        cache: false, //禁用缓存
        dataType: "json",
        data: {
            order_id: orderId, // 订单编号
        },
        success: function(result) {
            if (result.errorCode == 0) {
                var productList = $('.shun').find('.biaoge1-6');
                for (var j = 0; j < productList.length; j++) {
                    for (var i = 0; i < result.data.splitProductVOList.length; i++) {
                        if (result.data.splitProductVOList[i].productCode == $($($($(productList[j]).parent().children()[0]).children().children()[1]).children()[0]).html()) {
                            $(productList[j]).text(result.data.splitProductVOList[i].actualStock)
                        }
                    }
                }
                if (val == 2) {
                    $.Huimodalalert("刷新成功", 2000);
                }

            } else {
                $.Huimodalalert(result.msg, 2000);
            }



        },
    });


}
//扣额度
function deductionAmount() {
    $.ajax({
        type: "POST",
        url: root.orderInter.deductLimit,
        cache: false, //禁用缓存
        dataType: "json",
        data: {
            order_id: orderId, // 订单编号
        },
        success: function(result) {
            if (result.errorCode == 0) {
                $.Huimodalalert("成功", 2000);
                setTimeout(function() {
                    getOrdertail()
                }, 700);

            } else {
                $.Huimodalalert(result.msg, 2000);
            }



        },
    });
}
//订单类别修改
function modifyordercategory() {
    $(".noteditInformation").css({
        display: "none"
    });
    $(".editInformation").css({
        display: "inline"
    });
    $("#modifyordercategory").css({
        display: "none"
    });

    $(".preservationdatas").css({
        display: "inline"
    });
    $("#receipts").css({
        display: "inline"
    });

    loadingdata(1)
    var orderDetail = JSON.parse(sessionStorage.getItem("orderDetail"));
    $("#orderCategory").val(orderDetail.orderExt.order_big_type)
    if (orderDetail.specifyWarehouseCode != "" && orderDetail.specifyWarehouseCode != null) {
        $("#specifyProvinceCode").css({
            display: "inline"
        });
        $("#specifyProvinceCode").html('当前客户为' + orderDetail.specifyWarehouseName + '客户')
    } else {
        $("#specifyProvinceCode").css({
            display: "none"
        });
    }
}

//关联接货单
function receiptall(title, url) {
    sessionStorage.setItem("purchaseorderId", orderId)
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);

}

//加载下拉框数据
function loadingdata(val) {
    var orderDetail = JSON.parse(sessionStorage.getItem("orderDetail"));
    if (val == 1) {
        //发货仓
        $.ajax({
            url: root.orderInter.getAvailableWarehouses,
            contentType: "application/json",
            type: "POST",
            cache: false, //禁用缓存
            dataType: "json",
            data: JSON.stringify({
                "branchId": orderDetail.orderExt.belong_groupId,
                "orderBigType": $("#orderCategory").val(),
                "provinceId": orderDetail.orderExt.receiver_province_id,
                "cityId": orderDetail.orderExt.receiver_city_id,
                "areaId": orderDetail.orderExt.receiver_area_id,
                "townId": orderDetail.orderExt.receiver_town_id
            }),
            success: function(obj) {
                var deliverywarehouse = ""
                for (var i = 0; i < obj.data.length; i++) {
                    if (orderDetail.orderBase.warehouse_id == obj.data[i].warehouseId) {
                        deliverywarehouse += '<option value="' + obj.data[i].warehouseId + '" selected>' + obj.data[i].warehouseName + '</option>'

                    } else {
                        deliverywarehouse += '<option value="' + obj.data[i].warehouseId + '">' + obj.data[i].warehouseName + '</option>'

                    }
                }
                $("#deliverywarehouses").html(deliverywarehouse)
                loadingdata(2)
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                console.log(XMLHttpRequest);
            }
        });

    } else if (val == 2) {
        //订单类型
        $.ajax({
            url: root.orderInter.getAvailableOrderTypes,
            contentType: "application/json",
            type: "POST",
            cache: false, //禁用缓存
            dataType: "json",
            data: JSON.stringify({
                "branchId": orderDetail.orderExt.belong_groupId,
                "provinceId": orderDetail.orderExt.receiver_province_id,
                "cityId": orderDetail.orderExt.receiver_city_id,
                "areaId": orderDetail.orderExt.receiver_area_id,
                "townId": orderDetail.orderExt.receiver_town_id,
                "warehouseId": $("#deliverywarehouses").val(),
                "orderBigType": $("#orderCategory").val()
            }),
            success: function(obj) {
                var ordertype = ""
                for (var i = 0; i < obj.data.length; i++) {
                    if (orderDetail.orderExt.common_order_type == obj.data[i].orderType) {
                        ordertype += '<option value="' + obj.data[i].orderType + '" selected>' + obj.data[i].orderTypeName + '</option>'
                    } else {
                        ordertype += '<option value="' + obj.data[i].orderType + '">' + obj.data[i].orderTypeName + '</option>'

                    }
                }
                $("#ordertype").html(ordertype)
                loadingdata(3)
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                console.log(XMLHttpRequest);
            }
        });

    } else if (val == 3) {
        //配送方式
        $.ajax({
            url: root.orderInter.getAvailableSendTypes,
            contentType: "application/json",
            type: "POST",
            cache: false, //禁用缓存
            dataType: "json",
            data: JSON.stringify({
                "warehouseId": $("#deliverywarehouses").val(),
                "orderType": $("#ordertype").val(),
            }),
            success: function(obj) {
                var deliverymode = ""
                for (var i = 0; i < obj.data.length; i++) {
                    if (orderDetail.orderExt.sent_type == obj.data[i].sentType) {
                        deliverymode += '<option value="' + obj.data[i].sentType + '" selected>' + obj.data[i].sentTypeName + '</option>'

                    } else {
                        deliverymode += '<option value="' + obj.data[i].sentType + '">' + obj.data[i].sentTypeName + '</option>'

                    }
                }
                $("#deliverymode").html(deliverymode)
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                console.log(XMLHttpRequest);
            }
        });
        if ($("#ordertype").val() == 40116) {
            $("#receipts").css({
                display: "inline"
            });
        } else {
            $("#receipts").css({
                display: "none"
            });
        }
        if ($("#ordertype").val() == 40116 && orderDetail.orderExt.receipt_no != "") {
            $("#receivings").css({
                display: "inline"
            });
            $("#relationbillNo").html(orderDetail.orderExt.receipt_no)
        } else {
            $("#receivings").css({
                display: "none"
            });
        }
    }
}
//保存/取消
function preservationdatas(val) {

    if (val == 1) {
        //保存
        //验证
        changedeliveryWarehouse()
    } else if (val == 2) {
        //取消
        $(".noteditInformation").css({
            display: "inline"
        });
        $(".editInformation").css({
            display: "none"
        });
        $("#modifyordercategory").css({
            display: "inline"
        });

        $(".preservationdatas").css({
            display: "none"
        });
        $("#receipts").css({
            display: "none"
        });
        $("#specifyProvinceCode").css({
            display: "none"
        });
        $("#receivings").css({
            display: "none"
        });
    }
}
//发货仓列表信息
function changedeliveryWarehouse() {
    var user_data = {
        "operateUserId": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
        "operateUserName": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
        "orderId": orderId,
        "orderBigType": $("#orderCategory").val(),
        "warehouseId": $("#deliverywarehouses").val(),
        "commonOrderType": $("#ordertype").val(),
        "sentType": $("#deliverymode").val(),
        "receiptNo": $("#relationbillNo").html()
    }
    var succCallBack = function(data, status, response) {
        var skucodes = ''
        if (data.errorCode == "0") {
            if (data.data.checkCode == "0") {
                modifyAbnormalOrderInfo()
            } else if (data.data.checkCode == "1") {
                if (data.data.notExistsSkuList != "" && data.data.notExistsSkuList != null) {
                    for (var i = 0; i < data.data.notExistsSkuList.length; i++) {
                        skucodes += data.data.notExistsSkuList[i].skuCode + ",";
                    }
                    //去掉最后一个逗号(如果不需要去掉，就不用写)
                    if (skucodes.length > 0) {
                        skucodes = skucodes.substr(0, skucodes.length - 1);
                    }
                    $.Huimodalalert('sku' + skucodes + '在新发货仓中不存在，请修改发货仓', 2000);
                }
            } else if (data.data.checkCode == "2") {
                $("#changedeliveryWarehouse").modal("show")
                $("#warehouseName").html(data.data.warehouseName + "售价")
                $("#newWarehouseName").html(data.data.newWarehouseName + '售价')
                deliveryWarehouselist(data.data.changePriceSkuList)
            }
        } else {
            $.Huimodalalert(data.msg, 2000);
        }
    }
    web.doAjax(root.orderInter.checkOrderInfoChanges, 'post', user_data, succCallBack, 1);
}
//保存
function modifyAbnormalOrderInfo() {
    var user_data = {
        "operateUserId": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
        "operateUserName": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
        "orderId": orderId,
        "orderBigType": $("#orderCategory").val(),
        "warehouseId": $("#deliverywarehouses").val(),
        "commonOrderType": $("#ordertype").val(),
        "sentType": $("#deliverymode").val(),
        "receiptNo": $("#relationbillNo").html()
    }
    var succCallBack = function(data, status, response) {
        if (data.errorCode == "0") {
            $.Huimodalalert("修改成功", 2000);
            $("#changedeliveryWarehouse").modal("hide")
            $(".noteditInformation").css({
                display: "inline"
            });
            $(".editInformation").css({
                display: "none"
            });
            $("#modifyordercategory").css({
                display: "inline"
            });

            $(".preservationdatas").css({
                display: "none"
            });
            $("#receipts").css({
                display: "none"
            });
            $("#specifyProvinceCode").css({
                display: "none"
            });
            $("#receivings").css({
                display: "none"
            });
            getOrdertail()
        } else {
            $.Huimodalalert(data.msg, 2000);
        }
    }
    web.doAjax(root.orderInter.modifyAbnormalOrderInfo, 'post', user_data, succCallBack, 1);
}
//
function deliveryWarehouselist(data, index) {
    sessionStorage.setItem("authorizedUsers", JSON.stringify(data));
    dataSource.splice(0, dataSource.length); //清空数组


    if (data != null && data != '') {
        $.each(data, function(i, field) {
            var rowData = new Array();
            rowData.push(field.skuImage);
            rowData.push(field.skuCode);
            rowData.push(field.skuName);
            rowData.push(field.specifications);
            rowData.push(field.buyerCount);
            rowData.push(field.unit_name);
            rowData.push(field.originPrice);
            rowData.push(field.newPrice);
            dataSource.push(rowData);

        });
    }
    deliveryWarehouseDataTable(dataSource);

    function deliveryWarehouseDataTable(dataSource) {

        var dttable = $('#changedeliveryWarehousetable').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable
        $("#changedeliveryWarehousetable").DataTable({
            // "order": false,
            "autoWidth": false,
            "ordering": false,
            "searching": false,
            "paging": false,
            "retrieve": true,
            "destroy": true,
            "bAutoWidth": true,
            "bLengthChange": true,
            "aLengthMenu": false,
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据",
            },
            data: dataSource,
            columnDefs: [{
                    "visible": true,
                    "targets": 0
                },
                {
                    "render": function(data, type, row, meta) {
                        var val = '<div style="cursor:pointer;"><img  style="float: left;width: 100px;height: 100px;" name="" src="' + row[0] + '" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + row[1] + '</div><div>' + row[2] + '</div></div></div>'
                        return val;
                    },
                    "targets": 0
                },
                {
                    "render": function(data, type, row, meta) {
                        var val = ""
                        if (row[4] != "") {
                            val = row[4] + row[5]
                        }
                        return val;
                    },
                    "targets": 1
                }, {
                    "render": function(data, type, row, meta) {
                        var val = ""
                        if (row[6]) {
                            val = '' + row[6] + '元/' + row[5] + ''
                        }
                        return val;
                    },
                    "targets": 2
                },

                {
                    "render": function(data, type, row, meta) {
                        var val = ""
                        if (row[7]) {
                            val = '' + row[7] + '元/' + row[5] + ''
                        }
                        return val;
                    },
                    "targets": 3
                },

            ]
        });
    };
}
//暂不修改
function closeconfirmCollectison() {
    $("#changedeliveryWarehouse").modal("hide")
}
//最早送货时间计算
function earliestDeliveryTimeCalc(may_arrived_in) {

    var deliveryDateTime = new Date(may_arrived_in);
    deliveryDateTime.setHours(deliveryDateTime.getHours() - 2);
    var month = deliveryDateTime.getMonth() + 1;
    month = month < 10 ? "0" + month : month;
    var day = deliveryDateTime.getDate();
    day = day < 10 ? "0" + day : day;
    var hours = deliveryDateTime.getHours();
    hours = hours < 10 ? "0" + hours : hours;
    var minutes = deliveryDateTime.getMinutes();
    minutes = minutes < 10 ? "0" + minutes : minutes;
    var second = deliveryDateTime.getSeconds();
    second = second < 10 ? "0" + second : second;
    var newDate = deliveryDateTime.getFullYear() + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + second;
    return newDate + " - " + may_arrived_in;
}